+ 5

Adding an event listener

What is the problem with this js code i can't figure it out. I don't know how to ask it in a question. https://code.sololearn.com/WpodOJewvFu5/?ref=app

25th Nov 2020, 5:07 PM
Tharindu Warnapura
Tharindu Warnapura - avatar
3 Answers
+ 8
since js is loaded and executed first (unless you invoke it not to or add script tag after body), it does not know what the document has. wrap your DOM code inside a window.onload event so window.onload = () => { // your code }
25th Nov 2020, 5:12 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 5
PUT your js code inside window.onload=function() { } here's a good reference https://www.sololearn.com/post/7444/?ref=app
25th Nov 2020, 5:12 PM
Hima
Hima - avatar
25th Nov 2020, 5:29 PM
Tharindu Warnapura
Tharindu Warnapura - avatar