jQuery removeClass()

Introduction

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*ww  w  .  j  a  v  a2  s  .  co m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").removeClass("intro");
  });
});
</script>
<style>
.intro {
  font-size: 120%;
  color: red;
}
</style>
</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>Remove the "intro" class from all p elements</button>

</body>
</html>

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

If no parameter is specified, this method will remove all class names.

$(selector).removeClass(classname,function(index,current_class))
Parameter
Optional
Description
classname


Optional.


one or more class names to remove.
To remove several classes, separate the class names with space
If this parameter is empty, all class names will be removed
function(index,current_class)


Optional.


A function that returns one or more class names to remove
index - the index position of the element in the set
current_class - the current class name of selected elements



PreviousNext

Related