0

JavaScript probleme

Why document.write() is not working and also document.getElementById().innerHTML = "value"; They say some thin about innerHTML is null undefined ... I don't know if that's hapen only for me or what Thank you https://code.sololearn.com/WOyoQdj8Yapb/?ref=app

10th May 2020, 11:25 PM
youssef soufiane
youssef soufiane - avatar
3 Answers
+ 5
You should write it like this window.onload = function(){ document.getElementById("test").innerHTML = "ohayo"; } Anyway it's related to the sololearn interpreter...the js code is interpreted before html so when you call document.getElementById() he can't find the Id because html hasn't been read yet. So you put the code inside a function that gets called only when the window is loaded.
10th May 2020, 11:54 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar
+ 1
You should link your code so that I can try to help you
10th May 2020, 11:45 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar
0
Ah that's why it's not working Thank you👍
10th May 2020, 11:56 PM
youssef soufiane
youssef soufiane - avatar