How to delete class

Learn how to use JavaScript to remove class names from elements.

Click the button to remove a class from here!

delete class

Step 1 - Add HTML:

In this example, we will use a button to remove a class from id="myDIV" 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 of the specified class name:

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

Step 3 - Add JavaScript:

get id="myDIV" the <div> element, and remove "mystyle" class:

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

try it yourself

related pages

tutorial:Come commutare la classe

tutorial:Come aggiungere la classe

reference manual:Proprietà classList dell'Elemento DOM HTML

reference manual:Proprietà className dell'Elemento DOM HTML