Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

how to change a box's color in a grid back and forth from black and white

$
0
0

I have a 5x5 grid and what I'm able to do so far is only change the color of a box one way from white to black, but I need it to alternate between black and white every time I click on the box.

Frankly I'm stumped and don't know how to make it alternate I tried to find other examples but I couldn't find any. Currently the following javascript code can only change the box color from white to black.

var grid = document.getElementsByClassName("box");

Array.from(grid).forEach(click => click.addEventListener("click", function() {v.style.background = "black";}));

Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>