+ 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

18th Mar 2019, 1:40 PM
oh Common
oh Common - avatar
3 odpowiedzi
+ 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
18th Mar 2019, 5:08 PM
Gordon
Gordon - avatar
+ 1
It seems to be working for me. Console is not returning any error.
18th Mar 2019, 2:34 PM
Russ
Russ - avatar
+ 1
Gordon hey, thank you! Really helped me
18th Mar 2019, 9:00 PM
oh Common
oh Common - avatar