jQuery addClass: Main Tips
- jQuery
.addClass()
assigns a class to selected elements. - The function can be used on XML documents.
- You may use .removeClass() method to remove classes added with jQuery
.addClass()
.
How to Add Classes
The jQuery .addClass()
method applies a class for each matched element. In the example below, an element changes color and size upon clicking a button:
There are two kinds of syntax you might use:
$("selector").addClass(class);
- add aclass
you wish to apply. To add more than one class, separate them by spaces.$("selector").addClass(function);
- you might also name a function that returns a class name (or multiple) to be added.
Note: jQuery .addClass() method adds a class and does not replace the old ones.
Latest Coupon Found:
Verified STAFF PICK
TOP-RATED CODING COURSES
Learn the skills of tomorrow
The best time to learn programming is now - follow this link to access 100+ coding courses and enjoy learning at a very low cost!
Expiration date: 22/04/2021
2287 People Used
Only 92 Left