I’d like to be able to remove one class from a div and add another upon the click of a button. But I can’t get it to work.
<div class="hiddennav displaynone">
<ul>
<?php wp_nav_menu(array('menu' => 'Main Nav menu')); ?>
</ul>
</div> <!-- end div hiddennav -->
<div class="fixednav">
<div class="shownav"><a href="#" class="shownavbutton"></a></div>
<!-- end div shownav -->
</div> <!-- end div fixednav -->
Here’s the jQuery:
$(document).ready(function(){
$(".shownavbutton").click(function() {
$(".hiddennav").removeClass("displaynone").addClass("displayblock");
});
I’d preferably want it to toggle the classes too when clicked multiple times.
Try
$(selector).toggleClass(class):Optionally, you could use the CSS method as well (assuming that this is all you’re accomplishing via your
displaynoneanddisplayblockclasses):