jQuery removeClass() Method

The jQuery removeClass() method can be used to remove one or more class names from the selected element. It can also be used to change the class with another class name.

jQuery removeClass() Method

Syntax of removeClass() Method

The syntax of this method is given below:-

Remove a class
$(selector).removeClass(className)
Remove one or more classes
$(selector).removeClass(className1 className2 className3…)
Use Function to remove a class
$(selector).removeClass(function(index, current_class))
Remove old class and add new class
$(selector).removeClass(oldclassName).addClass(newclassName)

Description of the Parameters

The description of the parameters are given below.

Parameter Name Description
selector Specify the selector to select the elements and remove the class names. You have to use the tag name, class name, or id of the elements to select.
className It is the name of the class you have to remove from the selected element. You can add one or more class names separated by spaces.
index It returns the index position of the selected element.
current_class It returns the current class name of the selected element.
oldclassName Specify the name of the class you want to remove from the element.
newclassName Specify the name of the class you have to add to the element.

jQuery removeClass() Method Remove a Class From the Element

When you have to remove the single class name from the selected element, you can use this method. See the example given below that removes a specified class name. It also removes the CSS property added with the class name.

Example

Test it Live

Output

This is my paragraph

You have to click the button given above to remove the class names. The removed class contains the CSS properties which automatically get removed on class removal.

Remove One or More Classes Using the Method

The jQuery removeClass() method can also be used to remove more than one class name. You have to specify the class names with spaces as given in the example below. The example removes the two classes from the selected element.

Example

Test it Live

Output

This is my paragraph

When you click the button given above, it removes the two specified classes from the selected element. See the difference after you click the above button.

How to Replace One Class with Another Using jQuery

In addition to all the above, you can also use the method to replace the class names with another. You have to use jQuery removeClass() method with jQuery addClass() method as given below.

Example

Test it Live

Output

This is my paragraph

After you click the button, the class gets replaced with the new one. The new class also contains some styles that automatically gets added on class addition.

You may also like to read

I hope you like this tutorial on jQuery removeClass() method. If you have any queries regarding the tutorial, please comment below.

References