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

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

#1

Hello,

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: http://codepen.io/gry0/pen/BzOxwm

…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.

Thanks!


#2

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.


#3

Ohhhh, thanks! Makes sense!