Im trying to make a game board that has click functions on every cell, but every time i click on a cell the only one that gets affected is the very last cell. i would appreciate some help on this. heres my code for the table:
var board = document.getElementById("board");
var NUM_ROWS = 6;
var NUM_COLS = 6;
for (row = 0; row < NUM_ROWS; row++) {
var tr = document.createElement("tr");
for (col = 0; col < NUM_COLS; col++) {
var td = document.createElement("td");
var img = document.createElement("img");
img.src = 'images/image0.png';
td.appendChild(img);
td.addEventListener("click", function() {
img.src = 'images/image1.png';
});
tr.appendChild(td);
}
board.appendChild(tr);
}