EN
jQuery - remove class from div
6
points
In this article we can see how to dynamically remove one class from div
element using jQuery.
Quick solution:
$("#my-element").removeClass("my-class-2");
Full code example:
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
.my-class-1 { border: 2px solid red; padding: 5px; width: 200px; }
.my-class-2 { background: yellow; }
</style>
<script>
$(document).ready(function() {
$("#my-button").click(function() {
// HERE:
$("#my-element").removeClass("my-class-2");
});
});
</script>
</head>
<body>
<div id="my-element" class="my-class-1 my-class-2">Some text</div>
<button id="my-button" style="margin-top: 20px;">Remove class</button>
</body>
</html>