How to Remove Class in JavaScript from HTML Elements?
In JavaScript, you can remove a class from an HTML element using the classList
property and its remove()
method.
<script> button.classList.remove("highlight");</script>
How to Remove Class in JavaScript from HTML Elements
<!DOCTYPE html>
<html>
<head>
<title>Removing Class in JavaScript</title>
<style>
.highlight {
background-color: yellow;
}
</style>
</head>
<body>
<h2>Removing Class in JavaScript Example</h2>
<button id="myButton" class="highlight">Click Me</button>
<script>
// Remove class from the button
var button = document.getElementById("myButton");
button.classList.remove("highlight");
</script>
</body>
</html>