I add an event listener to every div out of my gird of 100divs. In the function I should be passing as a parameter the square which is clicked. The problem is the click() function only recongnizes the last div (number 99).
function createBoard(){
for(var i=0;i<width*height;i++){
var square=document.createElement('div');
grid.append(square);
square.setAttribute('id',i);
square.innerHTML=boardArray[i];
squares.push(square);
squares[i].addEventListener('click', function(e) {
click(square)
})
}//end for
}//end func
createBoard();
function click(square){
var id=square.id;
console.log(id) //displays 99th
}