.removeClass( [className ] ) Returns: jQuery
Description: Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
-
version added: 1.0.removeClass( [className ] )
-
classNameType: StringOne or more space-separated classes to be removed from the class attribute of each matched element.
-
-
version added: 1.4.removeClass( function(index, class) )
-
function(index, class)Type: Function()A function returning one or more space-separated class names to be removed. Receives the index position of the element in the set and the old class value as arguments.
-
If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If 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:
1
|
|
This method is often used with .addClass()
to switch elements' classes from one to another, like so:
1
|
|
Here, the myClass
and noClass
classes are removed from all paragraphs, while yourClass
is added.
To replace all existing classes with another class, we can use .attr('class', 'newClass')
instead.
As of jQuery 1.4, the .removeClass()
method allows us to indicate the class to be removed by passing in a function.
1
2
3
|
|
This example removes the class name of the penultimate <li>
from the last <li>
.
Examples:
Example: Remove the class 'blue' from the matched elements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
|
Example: Remove the class 'blue' and 'under' from the matched elements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
|
Example: Remove all the classes from the matched elements.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
|