- Trending Categories
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 10711 Articles for Web Development
![Ricky Barnes](https://www.tutorialspoint.com/assets/profiles/13354/profile/60_84969-1512590781.jpg)
94 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
![Ricky Barnes](https://www.tutorialspoint.com/assets/profiles/13354/profile/60_84969-1512590781.jpg)
684 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.
![Ricky Barnes](https://www.tutorialspoint.com/assets/profiles/13354/profile/60_84969-1512590781.jpg)
5K+ 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
![Alex Onsman](https://www.tutorialspoint.com/assets/profiles/13357/profile/60_91536-1512482971.jpg)
383 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?
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
3K+ Views
Both the methods are used in jQuery. Let’s see what purpose they fulfill.$(window).load()The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.$(document).ready()The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $( document ).ready() method will run once the page DOM is ready to execute JavaScript code.You can ... Read More
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
4K+ Views
The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.ExampleYou can try to run the following code to learn how to use $(window).load() method in jQuery −Live Demo $(document).ready(function(){ $("img").load(function(){ alert("Image successfully loaded."); }); }); Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
25K+ Views
The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ).ready() method will run once the page DOM is ready to execute JavaScript code.ExampleYou can try to run the following code to learn how to use $(document).ready() method in jQuery:Live Demo jQuery Function $(document).ready(function() { $("div").click(function() { alert("Hello, world!"); }); }); Click on this to see a dialogue box.
![David Meador](https://www.tutorialspoint.com/assets/profiles/13351/profile/60_165994-1512670078.jpg)
1K+ Views
To initialize jQuery in a web easy is quite easy. You can try to run the following code to learn how to initialize jQuery in a web page. We’re using Google CDN to add jQuery. Microsoft CDN is also available for the same purpose of adding jQuery library to HTML.ExampleLive Demo jQuery Function $(document).ready(function() { $("div").click(function() {alert("Welcome to Tutorialspoint!");}); }); Click on this to see a dialogue box.
![Alex Onsman](https://www.tutorialspoint.com/assets/profiles/13357/profile/60_91536-1512482971.jpg)
556 Views
To add and remove HTML attributes with jQuery, use the addClass() and removeClass() method.You can try to run the following code to add and remove HTML attributes with jQuery −ExampleLive Demo jQuery Example $(document).ready(function(){ $( '#add' ).click( function () { $('#page_navigation1').addClass( 'blue-class' ); }); $( '#remove' ).click( function () { $('#page_navigation1').removeClass( 'blue-class' ); }); }); .blue-class { background-color: blue; font-size: 30px; } Demo Add Remove
![Alex Onsman](https://www.tutorialspoint.com/assets/profiles/13357/profile/60_91536-1512482971.jpg)
1K+ Views
To remove all the attributes of an HTML element, the removeAttr() method won’t work. For this, create an array and use removeAllAttrs() to remove all the attributes of a specific HTML element. For example, remove the image by removing the attributes of the img element.You can try to run the following code to learn how to remove all the attributes from an element. We’re removing the img element attribute −ExampleLive Demo Selector Example $(document).ready(function() { $(".remove-attr").click(function(){ ... Read More