How to Remove Class Using Javascript?

In this article, we remove the CSS class using javascript. We create a simple text with some CSS and create a button. After clicking on the button call a javascript function and remove the class using javascript.

HTML

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div id="myDIV" class="mystyle"> Text with CSS</div> <br>

<button onclick="myFunction()">Remove Class</button>

</body>
</html>

CSS

.mystyle {
  width: 50%;
  padding: 25px;
  background-color: red;
  color: white;
  font-size: 25px;
  box-sizing: border-box;
}

Javascript

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

I hope this code will helpful for you.