I have no idea why this is not working. Seems like such a simple concept. I have some classes being toggled when a button is clicked. These classes just control the display of text open menu
and close menu
. That part is working, however, I need to have some additional scripts run when the button is clicked when its in it's opened state. When I click the button when it has the class opened
then nothing in my button.opened
click function happens.. it just runs the button.closed function. What am I doing wrong?
https://jsfiddle.net/dmcgrew/sfvhtahq/7/
$("button.closed").on("click", function(){
console.log("open the menu");
$(this).toggleClass("opened");
$(this).toggleClass("closed");
});
$("button.opened").on("click", function(){
//why does nothing in here happen?
console.log("close the menu");
$(this).toggleClass("opened");
$(this).toggleClass("closed");
});
.expand {width:100px; height:100px; background:red; display:block;}
.close, .open {display:none;}
.opened .close {display:inline;}
.closed .open {display:inline;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="expand closed"><span class="open">open menu</span><span class="close">close menu</span></button>