English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery removeClass() method

jQuery HTML/CSS Methods

The removeClass() method removes one or more class names from the selected elements.

If the class name is included as a parameter, only that class will be removed.

If the class name is not specified in the parameter, all classes will be removed.

Syntax:

Remove all classes

$.removeClass()

Remove the specified class

$.removeClass(className)

Use a function to remove a class

$.removeClass(function(index, currentClass))

Instance

Remove the class name "highlight" from all <p> elements:

$("button").click(function(){
  $("p").removeClass("highlight");
});
Test and see‹/›

One can remove more than one class (separated by spaces) from a set of selected elements, as shown below:

$("button").click(function(){
  $("p").removeClass("highlight big");
});
Test and see‹/›

If the class name is not specified in the parameter, all classes will be removed:

$("button").click(function(){
  $("p").removeClass();
});
Test and see‹/›

Use removeClass() to remove a class and add a new class using addClass():

$("button").click(function(){
  $("p").removeClass("red").addClass("green");
});
Test and see‹/›

Parameter Value

ParameterDescription
classNameSpecify one or more (separated by spaces) class names to be removed
Note:If this parameter is empty, all class names will be removed
function(index, currentClass)

Returns a function to remove one or more class names separated by spaces

  • index-Returns the index position of the element in the collection

  • currentClass-Returns the current class name of the selected element

jQuery HTML/CSS Methods