I currently use this code to hide and display a div:
<div id="showmenu">Click Here</div>
<div class="menu" style="display: none;"><ul><li>Button1</li><li>Button2</li><li>Button3</li></ul></div>
jQuery:
$(document).ready(function() {
$('#showmenu').click(function() {
$('.menu').slideToggle("fast");
});
});
When clicking on the div "Click Here" with id="showmenu", I want to add the class "active" to this div.
How can I achieve that?
You can use toggleClass:
$('#showmenu').click(function() {
$( this ).toggleClass("active");
$('.menu').slideToggle("fast");
});
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