How to toggle between true/false on click

Viewed 10761

I am using an .on click function to enable a setting. How would I modify this to say on click, toggle the (true) value from false to true and back again on the next click?

    $("#myBtn").on('click', function(){
            panorama.setVisible(true);
    });
1 Answers

you can achieve this by using a boolean

let isVisible = true;
$("#myBtn").on('click', function(){
    panorama.setVisible(isVisible);
    isVisible = !isVisible;
});

So everytime you click it, isVisible will swap between true and false

Related