+ 2

Javascript question: property

How to fix this error that appears when I use innerHTML or innerText in both of these. Uncaught TypeError: Cannot set property 'innerHTML' of null

2nd Oct 2020, 4:11 PM
Farhad Rahmani
Farhad Rahmani - avatar
13 Respostas
2nd Oct 2020, 4:16 PM
Farhad Rahmani
Farhad Rahmani - avatar
+ 1
Farhad Rahmani just wrapped it into window.onload = () => { // Your code should be here }
2nd Oct 2020, 4:23 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
🎃#H P 22™🎃 I think. His code doesn't have any bug or error. But sololearn behaves differently from browser. When you use js tab. It is good practice to wrap your code in window.onload
2nd Oct 2020, 4:29 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
Farhad Rahmani Did my code works?
2nd Oct 2020, 4:36 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
Javascript loads line by line so when it hits the line with innerHTML it gives an error because it haven't gotten anything with that class or id so it's very simple to resolve it just add your script tag at the end of body tag 🙌Happy Coding 🙌
4th Oct 2020, 2:48 PM
👑𝕻𝖗𝖔𝖌𝖗𝖆𝖒𝖒𝖊𝖗👑
👑𝕻𝖗𝖔𝖌𝖗𝖆𝖒𝖒𝖊𝖗👑 - avatar
0
🎃#H P 22™🎃 what is wrong in syntax?
2nd Oct 2020, 4:24 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
100 time i checked but that was perfectly correct.
2nd Oct 2020, 4:25 PM
Farhad Rahmani
Farhad Rahmani - avatar
0
Farhad Rahmani just wrap it into window.onload = () => { // Your code should be here }
2nd Oct 2020, 4:25 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
No i have coded in visual code but over here is also that kind of error.
2nd Oct 2020, 4:31 PM
Farhad Rahmani
Farhad Rahmani - avatar
0
2nd Oct 2020, 4:31 PM
Farhad Rahmani
Farhad Rahmani - avatar
2nd Oct 2020, 4:33 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
Vivek no bro sorry because over there have to shown day hour minute and seconds.
2nd Oct 2020, 4:38 PM
Farhad Rahmani
Farhad Rahmani - avatar
0
See one more time. do it works? https://code.sololearn.com/WN3BKy9a17Rn/?ref=app
2nd Oct 2020, 4:41 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar