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.
Try $(selector).toggleClass(class)
:
$(document).ready(function(){
$(".shownavbutton").click(function() {
$(".hiddennav").toggleClass("displaynone").toggleClass("displayblock");
});
});
Optionally, you could use the CSS method as well (assuming that this is all you're accomplishing via your displaynone
and displayblock
classes):
$(".hiddennav").toggle(function() {
$(this).css('display','none');
}, function() {
$(this).css('display','block');
});
Try this
$(".hiddennav").toggleClass("displaynone displayblock");