Uncaught TypeError: Cannot set properties of null | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Uncaught TypeError: Cannot set properties of null

Hi thanks for helping , when i create an element inside the html body , and i give it an id , like <p id="age"></p> and in Js when i want to set innerHTML for that element , it gives me Uncaught TypeError: Cannot set properties of null, even when i gave it id but still giving same problem , i have other code that doesnt have this problem , i don't know why this happen ? Note: i create elements inside <body></body> tags , here on soloLearn . But gives this error , while i have other code and done same thing here on SoloLearn and no problem it works , but now no matter i create any new web code and i want to id and element js see it as null , any one please have a solution for this ? Thanks https://code.sololearn.com/WFqpBh0Xuenx/?ref=app

10th Dec 2022, 11:50 AM
Halwest H
Halwest H - avatar
2 Antworten
+ 2
This is due to the fact that the JavaScript file is loaded before the html document. Use the boot delay feature: onload=()=>{ document.getElementById... ... }
10th Dec 2022, 1:08 PM
Solo
Solo - avatar
+ 1
Thanks alot man, i'm a noob still 😅i'm at the very beginning of this , hopefuly i learnt something new from you thank you very much 👍👍👍✌
10th Dec 2022, 1:15 PM
Halwest H
Halwest H - avatar