jquery remove class | How to use jquery removeclass() method to remove class from elements

jQuery provides method to remove one or more class names from given or selected elements.

Syntax of removeclass()

$(selector).removeClass(classname,function(index,currentclass))

For example, if you have multiple <p> tags in your page with different class names and want to remove a specific class:

$(“p”).removeClass(“orangetext”);

It will search through all P of document and then remove class orangetext wherever it will be found. All formatting will be removed, as specified in orangetext class.

$(“div”).removeClass(“demomenu”);

It will remove demomenu class from all div of document.

Please note, no ‘.’ (period) before specifying class name.

Example of using removeclass() method

This example will show how to remove a class and then its display impact. The orangetext class will be removed once ‘remove orange class’ link is clicked. All the formatting will be removed as well as that, that was made hidden in document.ready state will keep on showing, as it was made hidden on the basis of class name.



Removing multiple classes by using removeclass() method

More than one classes can be removed by using removeclass() method as follows:

$(“p”).removeClass(“exPgreenclass exPredclass exPorangeclass”);

This will remove exPgreenclass exPredclass exPorangeclass classes from <p> tags in document.

Example of removing multiple classes




Was this article helpful?

Related Articles

Leave A Comment?