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:
xxxxxxxxxx
1
$("#my-element").removeClass("my-class-2");
Full code example:
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
5
<style>
6
.my-class-1 { border: 2px solid red; padding: 5px; width: 200px; }
7
.my-class-2 { background: yellow; }
8
</style>
9
<script>
10
11
$(document).ready(function() {
12
$("#my-button").click(function() {
13
// HERE:
14
$("#my-element").removeClass("my-class-2");
15
});
16
});
17
18
</script>
19
</head>
20
<body>
21
<div id="my-element" class="my-class-1 my-class-2">Some text</div>
22
<button id="my-button" style="margin-top: 20px;">Remove class</button>
23
</body>
24
</html>