I have the following question? i have some divs and I want them to change background colors when i click on it. I have been searching on the internet and tried somethings out. now i can change the background color but i can't switch it back to the beginning. This is was I got so far. how can i make it so that it will toggle on each click. so first click, it turns black. second, it will turn white again and so on.
Do yourself a favor and take the time to learn some basic programming. While you can often find scripts that will do what you want, you'll always run into trouble with trying to modify the scripts you find. w3schools.com has a pretty decent course online. Give them a try.
In this case, you need to use a variable to keep track of the current color of the background. Then when your onclick() function is called, instead of simply applying the color specified, you can switch back and forth between two colors. Good luck!
Bookmarks