var cl = 0;
var menu = function(){
if(cl === 0){
$('.menu_nav').animate({left: '0px'}, 200);
$('body').animate({left: '285px'}, 200);
var cl = cl + 1;
console.log("First " + cl);
}else{
$('.menu_nav').animate({left: '-285px'}, 200);
$('body').animate({left: '0px'}, 200);
var cl = cl - 1;
console.log("Second " + cl);
};
};
$(document).ready(function(){
$('.menu-btn').on('click', function(){
$(menu);
});
});
I am attempting to create a toggle button that opens a side panel upon clicking, and then closes it when clicked again. I have experimented with += and =+ without success. Each click prints out "first 1," failing to transition to the 'else' statement as expected.
//The issue has been resolved by moving the declaration of the variable outside the function, preventing it from being reset to 0 every time the function is called. It now correctly stores and updates the variable value.