I am trying to loop through an array of html object and add a click event listener to every one of them. Reason for this is CSP.
problem is: it doesn't do it, no errors.. nothing...
Please help before I go insane.
var linkButtons = document.getElementsByClassName("navItem");
for(var i=0;i<linkButtons.length;i++){
linkButtons[index].addEventListener("click",function()console.log("e.e");});
}
function()console
-> function(){console
and make sure the document is loaded.
Corrected:
document.addEventListener("DOMContentLoaded", function(){
var linkButtons = document.getElementsByClassName("navItem");
for(var i=0;i<linkButtons.length;i++){
linkButtons[index].addEventListener("click",function(){console.log("e.e");});
}
});