So far I have managed to do this on single click.
const div = document.getElementById("sphere");
div.addEventListener("click", e => {
console.log("You clicked the mouse!");
div.style.backgroundColor = "white";
})
How do I make the circle div in the center change color from yellow to white and vice versa on every click inside the circle?
3
Answers
I would create one css class white (background white) and one yellow (background yellow). Then with js you just add or remove the class you want.
Or you can make it white by default and just create a yellow background class, then you use js toggle class which add or remove automatically a class https://www.w3schools.com/howto/howto_js_toggle_class.asp
Hope it helps
You can just try this way:
To do this without toggling classes you can create a variable to keep track of which color is being displayed. Something like this: