I have lots of small squares which have a class of "newDiv". I want to change their background color to black when mouse cursor are on them. However, I want them to stay the same(backgroundcolor black) even when mouse cursor is out. I'm trying to make my code work but I always get a syntax error or it does not work at all.
I've altered the code, tried to fix syntax etc.
black = true;
let tiles = document.getElementsByClassName('newDiv');
tiles.forEach(tile => {
tile.addEventListener('mouseover', function(e){
if(black){
tile.style.backgroundColor = "black";
}
})
}
Uncaught syntax error missing ) after argument list tiles.forEach is not a function.