I am trying to make this color "squares", which will change color after click. On first one it works fine, but when i click the others, the color change happens on the first one.
var image_tracker = 'red';
function changeColor() {
var image = document.getElementById('red')
if (image_tracker == 'red') {
image.style.backgroundColor = "blue";
image_tracker = 'blue';
} else {
image.style.backgroundColor = "red";
image_tracker = 'red';
}
}
<div id="red" onclick="changeColor()"></div>
<div id="red" onclick="changeColor()"></div>
<div id="red" onclick="changeColor()"></div>
there is no error messages, it just does not work as I would expect :D