jQuery deprecated toggle() method. It was way to easy to toggle classes, While searching stackoverflow I found various other methods to accomplish the same task( Alternative to jQuery's .toggle() method that supports eventData? ). Which jQuery snippet should be ideal to switch classes for this markup?
Thanks
Markup:
<a href="#">Toggle Class</a>
<div class="a"></div>
CSS:
.a{
background: #f2f2f2;
}
.b{
background: #ededed;
}
In this case, simply use .toggleClass().
$("a").click(function(){
$("div").toggleClass("a b");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With