- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10877 Articles for Web Development
813 Views
To get the input value of the first matched element using jQuery, use the .first() method.ExampleYou can try to run the following code to get the input value of the first matched element using jQuery −Live Demo $(document).ready(function(){ $( "li" ).first().css( "background-color", "blue" ); }); One Two Three Four
356 Views
jQuery comes with a lot of methods to manipulate attributes. These are DOM related methods. The attributes include, text() and html() too,text() – This method sets or returns the text content of elements selected.html() – This method sets or returns the content of elements selected.ExampleYou can try to run the following code to learn how to manipulate attributes with text() and html() methods −Live Demo $(document).ready(function(){ $("#button1").click(function(){ alert("Using text()- " + $("#demo").text()); }); $("#button2").click(function(){ alert("Using html()- " + $("#demo").html()); }); }); This is demo text. Text HTML
314 Views
To get the text contents of all matched elements using jQuery, use the text() method. You can try to run the following code to get text contents of all matched elements using jQuery −ExampleLive Demo The Selector Example $(document).ready(function() { $("#button1").click(function(){ var content = $("#pid2").text(); alert(content); }); }); .red { color:red; } .green { color:green; } This is first paragraph. This is second paragraph. Get
2K+ Views
To get the content of div which contains JavaScript script blocks, use the html() method. You can try to run the following code to get the content. With html(), get the content of div, which includes the JavaScript script.ExampleLive Demo $(document).ready(function(){ $("#button1").click(function(){ alert($("#demo").html()); }); }); This is demo text. This is JavaScript Get
3K+ Views
To get the innerHTML of a div tag in jQuery, use the class with innerHTML. You can try to run the following code to learn how to get innerHTML of a div tag using jQuery −ExampleLive Demo $(document).ready(function(){ $("#button1").click(function(){ var one = $('.a').innerHTML; alert(one); }); }); Value one Get
2K+ Views
To replace innerHTML of a div tag, use the html() method. The dot notation calls the html() method to replace the inner html with the parameter placed between, i.e. Demo here. The html() here modifies the .innerhtml.ExampleYou can try to run the following code to to replace innerHTML of a div tag using jQuery −Live Demo $( document ).ready(function() { $('.myclass').html('Demo'); }); Hello World
82 Views
The html() method sets or returns the content of elements selected. jQuery has a some methods to manipulate attributes, including the html() method. These are DOM related methods. The attributes include, text() – This method sets or returns the text content of elements selected.html() – This method sets or returns the content of elements selected.val() – This method sets or returns the value of form fields.ExampleYou can try to run the following code to learn how to work with html() method −Live Demo $(document).ready(function(){ $("#button1").click(function(){ alert("Using text- " + $("#demo").text()); ... Read More
652 Views
To toggle between two classes in jQuery, use the addClass() and removeClass() method. You can try to run the following code to toggle between two classes in jQuery −ExampleLive Demo $(document).ready(function(){ $("a").click(function(){ $("a.active").removeClass("active"); $(this).addClass("active"); }); }); .active { font-size: 22px; } One Two Click any of the link above and you can see the changes.
4K+ Views
To remove all classes, use the removeClass() method with no parameters. This will remove all of the item's classes.ExampleYou can try to run the following code to remove all CSS classes using jQuery:Live Demo jQuery Selector $(document).ready(function() { $("#button1").click(function(){ $("p").removeClass(); }); }); .red { color:red; } .blue { color:blue; } This is first paragraph. This is second paragraph. Remove
359 Views
The hasClass() method is used to check if an element has a class in jQuery. jQuery is a JavaScript library introduced to make development with JavaScript easier. It reduces the development timeExampleYou can try to run the following code to check if an element has a class in jQuery −Live Demo $(document).ready(function(){ $("button").click(function(){ alert($("h1").hasClass("myclass")); }); }); .myclass { color: blue; } Heading This is demo text. Check: The h1 element has 'myclass' class?
To Continue Learning Please Login
Login with Google