xxxxxxxxxx
jQuery( "button.hamburger" ).click(function() {
jQuery(this).toggleClass( "is-active" );
});
xxxxxxxxxx
$('.ButtonClass').on('click', function(e) {
$('.Items').toggleClass("toggleyour CLASS"); //Target Div where toggle class
e.preventDefault();
});
xxxxxxxxxx
// HTML element to toggle class on
var element = $('#myElement');
// Function to toggle the class
function toggleClass() {
element.toggleClass('myClass');
}
// Call the toggleClass function
toggleClass();
xxxxxxxxxx
// add class [class-name] if condition is true
// or else remove it
$('#foo-bar').toggleClass('class-name', condition)
xxxxxxxxxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>toggleClass demo</title>
<style>
p {
margin: 4px;
font-size: 16px;
font-weight: bolder;
cursor: pointer;
}
.blue {
color: blue;
}
.highlight {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
</head>
<body>
<p class="blue">Click to toggle</p>
<p class="blue highlight">highlight</p>
<p class="blue">on these</p>
<p class="blue">paragraphs</p>
<script>
$( ".blue" ).on( "click", function() {
$( this ).toggleClass( "highlight" );
});
</script>
</body>
</html>