I have created a switch in my website. It works like a light switch. When people click on it, the background color and the color of some text paragraph will switch to different colors. I wrote the code below and successfully did the task:
$(".clickme").click(function () {
$('html').css('background-color', 'black');
$('#top_nav a').css('color', '#ff7b00');
$('.back_face').css('background-color', 'black');
return false;
});
But now I want to turn the light back on. I have created a var called lighton, and set it to 0. And I tried to use an if else statement to do the task, but it doesn't work. Below is the code I wrote and failed:
<a href="" class="clickme">Click me</a>
<script>
$(".clickme").click(function () {
var lightoff = 0;
if (lightoff=0){
$('html').css('background-color', 'black');
$('#top_nav a').css('color', '#ff7b00');
$('.back_face').css('background-color', 'black');
lightoff = 1;
return false;
}else{
$('html').css('background-color', 'white');
$('#top_nav a').css('color', 'black');
$('.back_face').css('background-color', 'white');
lightoff = 0;
return false;
}
});
</script>
I just started learning JavaScript recently, and I have checked the JavaScript Conditional Statements syntax. So I hope somebody knows what's wrong with my code. Thank you so much.
var lightoff = 0;out of yourclick()event