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 RĂ©ponses
+ 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);
}