+ 5

Why do I have this error?

It always happens to me and I do not understand why :( https://code.sololearn.com/WReSV7m3sdaA/?ref=app

25th Aug 2018, 1:14 AM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
2 Respuestas
+ 3
It's because the JS is getting loaded before the webpage itself. You need to wrap the entire JS code inside a function which fires after the window has been loaded. Do this, window.onload= function(){ //Your JS goes here }
25th Aug 2018, 1:28 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Look the body tag: <body onload="func()"> <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body onload="func()"> <div id="one"></div> </body> </html> JS: function func(){ var one = document.querySelector("#one"); one.innerHTML = "one"; }
25th Aug 2018, 3:50 PM
Mr Genesis
Mr Genesis - avatar