<html>
<head>
<style>
.mystyle {
width: 500px;
height: 50px;
border: 1px solid black;
}
.anotherClass {
background-color: lightblue;
padding: 25px;
}
.thirdClass {
text-align: center;
font-size: 25px;
color: navy;
margin-bottom: 10px;
}
</style>
</head>
<body>
<p>Click the button to find out if the DIV element has a class of "mystyle". If so, remove "anotherClass".</p>
<div id="myDIV" class="mystyle anotherClass thirdClass">
I am a DIV element
</div>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> The classList property is not supported in Internet Explorer 9 and earlier versions.</p>
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.classList.contains("mystyle")) {
x.classList.remove("anotherClass");
} else {
alert("Could not find it.");
}
}
</script>