0

Why this error?

I am trying since yesterday but it's not working I have no idea what's wrong in this code why iam getting error of null? https://code.sololearn.com/WM5n3x9ExE6o/?ref=app

13th Feb 2021, 1:13 PM
Technical Code
Technical Code - avatar
4 ответов
+ 4
Javascript is getting executed before html dom loads because sololearn places javascript files inside head tag which means there is no button element yet and so trying to get it and performing some operation on it gives you an error . Simply place your js code (dom interaction one) inside the onload function which will execute js code only after html dom is loaded. onload=()=>{ }
13th Feb 2021, 1:26 PM
Abhay
Abhay - avatar
+ 3
You script ran before your html was loaded Have a look on this https://code.sololearn.com/WrHklCptM0m2/?ref=app
13th Feb 2021, 1:23 PM
KashishAggarwal
KashishAggarwal - avatar
+ 3
https://code.sololearn.com/W1gDjWO5ZvJB/?ref=app
13th Feb 2021, 1:26 PM
#It's Tony Stark
#It's Tony Stark - avatar
+ 1
Thank you very much everyone for resolving my issue❤️
13th Feb 2021, 1:37 PM
Technical Code
Technical Code - avatar