I wrote simple code to show/hide some layers after clicking buttons (5 in total) and to change color of the clicked buttons. That works fine. But then I wanted to show a certain element - an arrow - only after clicking first button using a boolean variable and it's not working, the if statement never returns first (hooray) part. What am I missing?
var click01 = false;
function allowright1() {
if (click01 == true) {
console.log('hoooray');
$('#right_arrow').removeClass('hidden').addClass('visible');
} else {
console.log('not working');
}
};
$('#tile1_p1').click(function() {
if ($('#1layers1').css('display') == 'none') {
$('#1layers2, #1layers3, #1layers4, #1layers5').removeClass('block').addClass('none');
$('#tile2_p1, #tile3_p1, #tile4_p1, #tile5_p1').removeClass('orange');
$('#1layers1').removeClass('none').addClass('block'); $('#tile1_p1').removeClass('white').addClass('orange');
var click01 = true;
console.log('click01 ' + click01);
allowright1();
}
else if ($('#1layers1').css('display') == 'block') {
$('#1layers1').removeClass('block').addClass('none');
$('#tile1_p1').removeClass('orange').addClass('white');
}
});
varwithclick01 = true;in the event handlersvar click01, you are declaring the variable, you are assigning value to the global variable, just removedvarkeyword and you are done!