I have a button and I want my variable click
to be set to true
when the button is clicked, and false
when the button is clicked again (I want toggle functionality).
When click == true
, I want it to output clicked
into the console and when click == false
I want it to output not clicked
.
var click = false
Here's my toggle function:
$('.button').toggle(
function(){
click = true;
$('.bmw').show();
}, function() {
click = false;
$('.bmw').hide();
});
And what I want it to do:
if(click = true) {
console.log('clicked');
} else {
console.log('not clicked');
}
When I load the page the console shows not clicked
but when I press the button it doesn't switch to true
. The bmw objects** .bmw
do however show and hide when I toggle the button so that seems to be working fine.
What am I doing wrong?