I just ran into a problem. On my site I need to have possibility to open or close menu item by click of the button.
On button click :
var checked = true;
function NotifierButtonClicked() {
if (checked == true) {
checked = false;
GetNotificationsForUser();
$('.selectBox').slideToggle(200).css('borderTop', 'none');
$('.selectBox li').click(function () {
$('.selectBox').slideUp(200);
});
}
if (checked == false) {
checked = true;
$('.selectBox').slideUp(200);
}
}
So problem here is that when I enter if block first time, checked is true, so I slide menu up and set checked to be true. Next time I click on button checked is true so menu will open up, but I set checked to be false so when code gets to next if condition it will run too and close menu right away. How to solve this problem?
Use
ifand thenelse if