Javascript DOM HTML Element classList Property remove a class

Introduction

Remove a class from a <div> element:

document.getElementById("myDIV").classList.remove("mystyle");

Click the button to remove the "mystyle" class from DIV.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {//from  w w w  .  j  a  va 2s .co m
  width: 300px;
  height: 50px;
  background-color: coral;
  color: white;
  font-size: 25px;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV" class="mystyle">
I am a DIV element
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").classList.remove("mystyle");
}
</script>

</body>
</html>



PreviousNext

Related