The following will only select the first element with class='cell'
.
document.querySelector('.cell');
For adding event listener to all such elements, use querySelectorAll()
,
which will return a NodeList
(a kind of array of inactive DOM elements) having class='cell'
. You need to iterate over it or access specific element using it's index.
For example:
var cells = document.querySelectorAll('.cell');
cells.forEach(cell => cell.addEventListener('mouseover', callback, false));
Check this fiddle