+ 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

7th Jan 2018, 12:53 PM
Mark Pozsar
Mark Pozsar - avatar
5 odpowiedzi
+ 7
window.onload = function () { var elem = document.getElementById("demo"); elem.innerHTML = "Hello World!"; }
7th Jan 2018, 12:58 PM
Calviղ
Calviղ - avatar
+ 6
use windows onload event. ie.👇👇👇 window.onload=function(){ elem = document.getElementById("demo"); elem.innerHTML = "Hello World!"; }
7th Jan 2018, 12:59 PM
MR Programmer
MR Programmer - avatar
+ 5
Yes, if in the JS pane. Because the code loaded in head tag before the HTML elements load.
7th Jan 2018, 1:03 PM
Calviղ
Calviղ - avatar
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?
7th Jan 2018, 1:01 PM
Mark Pozsar
Mark Pozsar - avatar
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?
7th Jan 2018, 1:14 PM
Mark Pozsar
Mark Pozsar - avatar