+ 2
Code Not Working
I was trying to do a code using what I learned about DOM so far, and it's not working, the console is saying that the var with a element from HTML is null. https://code.sololearn.com/WDtw9AtV56v0/?ref=app
3 ответов
+ 4
1. Put your codes in window.onload
2. Demo:
https://code.sololearn.com/WgloMkSRQhmx/?ref=app
3. Explanation:
The codes in JS tab runs before the DOM exists. Because they are put inside head element when compiling.
4. Further explanation :
Another way to solve this is putting the scripts at end of body element.
5. This code by Calvin best demonstrates the sequence of execution :
https://code.sololearn.com/W8qiO41gHNfu/?ref=app
+ 1
It seems to be working for me. Console is not returning any error.
+ 1
Gordon hey, thank you! Really helped me