+ 1

why is addEventListener in Javascript not available in solo learn?

addEventListener is not working on my code in javascript https://code.sololearn.com/WlWcn4rRrAN9/?ref=app

13th Aug 2021, 11:04 AM
James Romerosa
James Romerosa - avatar
3 Respuestas
+ 3
Write your JavaScript inside this then it will work window.onload=()=>{ // JavaScript here };
13th Aug 2021, 11:54 AM
VSR [ DEV ]
VSR [ DEV ] - avatar
+ 6
The problem is not exactly the addEventListener but that the variable that should hold the button is null at the time you try to add the listener. One solution could be, to put your js inside onload = () => { here goes your js... }
13th Aug 2021, 11:20 AM
Lisa
Lisa - avatar
+ 2
thanks guys it works!
13th Aug 2021, 11:59 AM
James Romerosa
James Romerosa - avatar