0

getElementById().innerHTML doesn’t work...

When I try to output something using the method document.getElementById().innerHTML I only get an error message. What’s wrong with my code? https://code.sololearn.com/WXElTLe26qiw/?ref=app

22nd Jun 2018, 2:17 AM
Galileo
1 Respuesta
+ 10
The DOM isn't ready yet, so you were trying to change a paragraph's content before the paragraph element was created/rendered by browser. Wrap such code inside an onload event handler function as follows: window.onload=function(){ document.getElementById("demo").innerHTML = "This is a paragraph."; } Hth, cmiiw
22nd Jun 2018, 2:28 AM
Ipang