+ 1
JS error only in playground
Why i gets this error on sololearn playground while the code works on repl.it? "Cannot set property 'innerHTML' of null" my code html: <!DOCTYPE html> <html> <head> <title>repl.it</title> </head> <body> <p id="demo">hello</p> <script src="script.js"></script> </body> </html> js: var a=document.getElementById("demo"); a.innerHTML="how r u"; code works fine on repl
6 ответов
+ 2
ah! my mistake, its window.onload not body
+ 2
use load event, maybe js run before the page able to render anything
body.onload = function(){
// js here
}
+ 1
thanks but didnt worked
+ 1
ur guess was right i put the function in setTimeout and it worked.
+ 1
lol i hate some alphabates of function of js are capitalize :p
+ 1
oh lol; thanks though