Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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 Respostas
+ 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);
}