0
Cant set property textContent of null
Hello, it happens me a lot here when I use a textContent or innerHTML property that I get an error saying uncaught typeError: can't set textContent / innerHTML property of null. var hello = document.getElementById("hello") ; hello.textContent = "Sololearn" ; I get an error and cant output it, while when I try it on the desktop I can do It without problems. Why is that?
6 Respostas
+ 2
David , you should add in the beginning of JS window.onload. Look at the code and hope it helps you 🐱
https://code.sololearn.com/Wb6y6vXxMp7N/?ref=app
0
David , can you show the whole code linked to Playground, so somebody can help you.
0
Lol, I knew it was something funny. I've never even used onload function. Thanks a lot for help!
0
David , you are welcome. It's because you should first load all html content before you use it, when it is in separate JS file.
0
Ohh.. I never paid attention to this... This is obviously very important... Thanks a lot :)