Adding and Removing Class with jQuery

Adding and Removing Class with jQuery When you are using jQuery, adding and removing a single class, multiple classes, or all classes from each HTML element is possible.

How to Use removeClass()Method?

If a class name is included as a parameter, then only that class will be removed from the set of matched HTML elements. If there is no class names are specified in the parameter, all classes will be removed.

More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:

$( "p" ).removeClass( "myClass yourClass" )

How to Use addClass()Method?

addClass() method adds the specified class(es) to each of the set of matched HTML elements.

IMPORTANT: Please note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the HTML elements.

More than one class may be added at a time, separated by a space, to the set of matched elements, like so:

$( "p" ).addClass( "myClass yourClass" );

addClass() and removeClass() Method Sample Usage



jQuery gives you ability to add and remove class(es9 by using 2 methods. You can use addClass() and removeClass() methods for playing with classes


addClass()  removeClass()  add class  remove class