I am using this code to add a function when buttons are clicked, but it's not working.
function onClick(){
console.log("Button pressed.");
localStorage.counter = ++counter;
console.log(counter);
}
window.addEventListener('load', function() {
console.log("Loaded");
var buttons = document.getElementsByClassName("v-btn v-btn--small theme--dark orange");
console.log(buttons);
console.log("buttons.length:")
console.log(buttons.length);
var i;
for(i = 0;i < buttons.length;i++){
buttons[i].onclick = onClick();
console.log("Event added")
}
}, false);
When page loads I only get this in the console: Chrome Console output
Also nothing happens when I click on the buttons. If I debug it with breakpoints in chrome the output will change and it will say that the buttons is empty.
EDIT: The problem is that its not even entering for loop.
EDIT2: The buttons don't appear when load event is called. window.addEventListener('load') is executing too early