removeClass() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:removeClass

Description

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

Syntax

$(selector).removeClass(classname,function(index,currentclass));
ParameterRequire Description
classnameOptional. one or more class names to remove.
function(index,currentclass) Optional. A function that returns one or more class names to remove

To remove several classes, separate the class names with space

If classname parameter is empty, all class names will be removed

  • index - the index position of the element in the set
  • currentclass - the current class name of selected elements

The following code shows how to Remove the class name "intro" from all <p> elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.intro {/*from w ww.j  a  v a  2 s. c o m*/
    font-size: 120%;
    color: blue;
    background-color:#EEE;
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").removeClass("intro");
    });
});
</script>
</head>
<body>

<h1>This is a heading</h1>

<p class="intro">This is a paragraph.</p>
<p class="intro">This is another paragraph.</p>

<button>test</button>

</body>
</html>

Related Tutorials