Help with Wiki Viewer JQuery - switch background back & forth [Solved]


I’m trying to implement an event using jQuery to change the background color of a div when clicked, and then switch it back to the original background color when it’s clicked again. I tried doing it this way:

…but it’s not working, and I can’t figure out why.

I don’t think I’m actually implementing this in my final project, but I’m very curious as to why it’s not working.


Hey, it doesn’t work because you set counter to zero everytime the button is clicked. If you put var counter = 0; outside the event handler it does work.

1 Like

Ohhhh, thanks! Makes sense!