0
Why won’t my addEventListener work?
https://code.sololearn.com/W60ks5SBnd88/?ref=app I’m using document.execCommand to create HTML when a button is pressed. Within the HTML created, is a class that I’m trying to access so I can create a usable button by pressing the first button. But I can’t do this because the addEventListener won’t work with the class created and I’m not sure why. This is on line 42. If anyone has any tips or info they can offer, that would be much appreciated.
2 Respuestas
+ 1
It was a scope problem. The addEventListner needed to be within the function where the HTML was being generated.
+ 2
FYI, just in case this is useful
function handleClick(event){
alert(event); // object MouseEvent
}
window.onload = function(){
document.querySelector("#clickme").addEventListener("click", handleClick, false);
}