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
1 Odpowiedź
+ 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