jQuery removeClass() Attribute

The removeClass() method is used to remove one or more class names from the selected elements.

Syntax of removeClass() Attribute

$(selector).removeClass(classname) 

The selector is the element from which class to be removed. The 'classname' is the required parameter. It specifies one or more class names to remove. To remove multiple classes, separate each class names with a space.

Example - remove single class

<style>
.cls { 
font-size: 22px;
}
.txt {
font-style: italic; 
}
.clr { 
color: blue;
}
</style>

<p id="demo" class="cls txt clr"> Hello World!</p>

<script>
$(document).ready(function(){
$("p#demo").removeClass("cls");
});
</script>

Output of the above code

Hello World!

In the above example, 'cls' class name is removed from the class of the paragraph of id 'demo'.


Example - remove multiple classes

<style>
.cls { 
font-size: 22px;
}
.txt {
font-style: italic; 
}
.clr { 
color: blue;
}
</style>

<p id="para" class="cls txt clr"> Hello World!</p>

<script>
$(document).ready(function(){
$("p#para").removeClass("txt clr");
});
</script>

Output of the above code

Hello World!

In the above example, 'txt' and 'clr' class names are removed from the class of the paragraph of id 'para'.



Read more articles


General Knowledge



Learn Popular Language