How to Remove Class

Learn how to remove a class from an element using JavaScript.

Click the button to remove a class from here!

Remove Class

Step 1 - Add HTML:

In this example, we will use a button to remove a class from id="myDIV" from the <div> element "mystyle" Class:

<button onclick="myFunction()">Try It</button>
<div id="myDIV" class="mystyle">
  This is a DIV element.
</div>

Step 2 - Add CSS:

Set the style for the specified class name:

.mystyle {
  width: 100%;
  padding: 25px;
  background-color: coral;
  color: white;
  font-size: 25px;
}

Step 3 - Add JavaScript:

Get id="myDIV" from the <div> element, and remove "mystyle" Class:

function myFunction() {
  var element = document.getElementById("myDIV");
  element.classList.remove("mystyle");
}

Try It Yourself

Related Pages

Tutorial:How to Toggle Class

Tutorial:How to Add Class

Reference Manual:HTML DOM Element classList Property

Reference Manual:HTML DOM Element className Property