+ 1

Uncaught TypeError?

it said Uncaught TypeError: Cannot read property 'addEventListener' of null Line: 3 https://code.sololearn.com/WZt0O6ZdvL8o/#html

13th Apr 2019, 12:25 AM
Glory222
Glory222 - avatar
3 ответов
+ 5
Glory S its too common error beginner gets here. Its just that your JS gets loaded before the html window and hence it cannot find the html element you're adding eventListener to thus its null. You need to warp you JS code inside a function which will be called once the html window gets loaded. You can do it like window.onload =function () { //your JS code goes here }
13th Apr 2019, 12:31 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Thank you bro
13th Apr 2019, 2:16 AM
Glory222
Glory222 - avatar