+ 1
Change element with Javascript issue, not working.
Hi, could you please help. The method provided in the Sololearn lesson is not working. I copied it straight from the lesson but I keep getting an error message. I am starting to lose my mind at this point wtf 😂 https://code.sololearn.com/WYYHly0X5oHi/?ref=app
5 Réponses
+ 7
window.onload = function () {
var elem = document.getElementById("demo");
elem.innerHTML = "Hello World!";
}
+ 6
use windows onload event.
ie.👇👇👇
window.onload=function(){
elem = document.getElementById("demo");
elem.innerHTML = "Hello World!";
}
+ 5
Yes, if in the JS pane. Because the code loaded in head tag before the HTML elements load.
0
thx guys, idk why the hell that part was not provided in the lesson.
Do I have to nest every getElement... in a windows.onload function?
0
I see, so I wouldn't need the windows.onload function if the js code was nested in the Html with script tags?
Are there other ways to link a js code to the html externally other than windows.onload=function? Does sololearn provide a lesson to list these and explain how they differ?