I have following code
var el = document.querySelectorAll(\'.block\');
console.log(el);
el.addEventListener(\'click\', function () {
alert(\'hello\');
},
Because, exactly as the error message tells you NodeLists don't have an addEventListener method. You should iterate over the nodelist, and addEventListener
to each element within – assuming that you want to add N listeners.
Alternately, select only a single element, and the remainder of your code will work as written.