I can't use innerHTML | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

I can't use innerHTML

I tried adding innerHTML to my Java script but it said that the property can't be read. Here's my code.. https://code.sololearn.com/W7ZoQ7XXDh1p/?ref=app

17th Jun 2018, 3:07 AM
Renz Frederick BaƱas
Renz Frederick BaƱas - avatar
5 Respostas
+ 8
That is because your script loaded before the document did. Wrap it in an onload function. window.onload = function() { var y = document.getElementById("demo"); y.innerHTML = "another demo text"; }
17th Jun 2018, 3:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
You should check this, explain a little more why that happens: https://www.sololearn.com/post/7444/?ref=app
17th Jun 2018, 3:15 AM
Mickel
Mickel - avatar
0
Hatsy Rei Okay I added it to the script but the text did'nt change...
17th Jun 2018, 3:15 AM
Renz Frederick BaƱas
Renz Frederick BaƱas - avatar
0
Asteck 1263 You have a typo there. It's window.onload not window.unload so change u to o, then it will work
17th Jun 2018, 3:31 AM
Matthias
Matthias - avatar
0
but how can you set intervals for the change... like wait 5 seconds before changing?
17th Jun 2018, 3:41 AM
Renz Frederick BaƱas
Renz Frederick BaƱas - avatar