Change a boolean back and forth javascript -


i wonder if possible in javascript have click event listener every time click changes boolean true false , forth. meaning click 1 goes false, click again , goes true , on in infinite loop. don't know if possible tried this:

//this listener circlepicker.click(function () {     booleanchecker(circlepickerselector);     console.log(booleanchecker(circlepickerselector)); });  //this function checks if boolean true or false function booleanchecker(isthistrue) {     // circlepickerselector = !circlepickerselector;     // return circlepickerselector;     if (isthistrue == false) {         isthistrue = true;         console.log("i turned true");     } else if (isthistrue == true) {         isthistrue = false;         console.log("i turned false");     }     return isthistrue; } 

i know if possible. feeling wrong in syntax. suggestion more welcome.

thanks!

you can toggle using ! operator

circlepicker.click(function () {     circlepickerselector = !circlepickerselector;     console.log(circlepickerselector); }); 

if circlepickerselector true, !circlepickerselector turns false. can assign same variable reverse on next click.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -