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 Udacity Coupon Found:
Verified STAFF PICK
75% OFF COURSES
Udacity Black Friday Offer
The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!
Expiration date: 18/01/2021
3176 People Used
Only 97 Left