+ 7
[Solved]Why addEventListener not working?
5 Respuestas
+ 8
You must apply any JS only after the page content is loaded. So you should put it inside window.onload like this.
window.onload = () =>{
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
}
Read this for reference.
https://www.sololearn.com/post/7444/?ref=app
+ 8
Thank you Avinesh sir
+ 6
You should use window.onload to make it work
https://code.sololearn.com/WiitLCKU3p0l/?ref=app
+ 6
Thank youHarsh [Less active]
+ 4
Ansheeta you're welcome.
And just Avinesh is fine.