.removeClass()
methodThe .removeClass()
method in jQuery is used to remove the class(es) from the matched elements.
.removeClass()
method Syntax$.removeClass() $.removeClass('className') $.removeClass('className className') $.removeClass(function)
Parameter | Type | Description |
---|---|---|
className |
String | the class name to be removed from class-attribute of each matched element |
funtion(index, oldClassName) |
Function | a function returning one or more space-separated class names to be removed. index is the position of the element in the set.(based 0) oldClassName is/are old class name(s). |
.removeClass()
Remove all the class name from the matched elements.
HTML
<p>JavaScript Tutorial</p> <p class="selected">JavaScript Examples</p> <p class="box selected">Learn JavaScript on Lautturi.com</p>
jQuery
$("p").removeClass();
Result
<p class>JavaScript Tutorial</p> <p class>JavaScript Examples</p> <p class>Learn JavaScript on Lautturi.com</p>
.removeClass('className')
Remove the class "selected" from the matched elements.
$("p").removeClass("selected");
.removeClass('className className')
Remove the class 'blue' and 'under' from the matched elements.
jQuery
$( "p" ).removeClass( "blue under" );
HTML
<p class="blue under">JavaScript Tutorial</p> <p class="blue">JavaScript Examples</p> <p class="under">Learn JavaScript on Lautturi.com</p> <p class="blue under highlight">Learn JavaScript on Lautturi.com</p>
Result
<p class>JavaScript Tutorial</p> <p class>JavaScript Examples</p> <p class>Learn JavaScript on Lautturi.com</p> <p class="highlight">Learn JavaScript on Lautturi.com</p>
.removeClass(function)
Remove the class "item-*" from matched elements.
HTML
<ul> <li class="item-0">Hello</li> <li class="item-1">Hello</li> <li class="item-2">Hello</li> </ul>
jQuery
$('ul li').removeClass(function(index) { return "item-" + index; });
Result
<ul> <li>Hello</li> <li>Hello</li> <li>Hello</li> </ul>