Element classList Property - Remove a class from a <div> element: - Javascript DOM

Javascript examples for DOM:Element classList

Description

Element classList Property - Remove a class from a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {/*from w w  w  . j a va 2  s .  c o m*/
    width: 500px;
    height: 50px;
    padding: 15px;
    border: 1px solid black;
}

.anotherClass {
    background-color: coral;
    color: white;
}

.thirdClass {
    text-transform: uppercase;
    text-align: center;
    font-size: 25px;
}
</style>
</head>
<body>

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

Related Tutorials