Could someone help me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Could someone help me?

Why is the background of this page not red? Instead it causes "Uncaught TypeError" and "Cannot read property 'style' of undefined." What did I do wrong? https://code.sololearn.com/WM2Uy2rn7SM8/?ref=app

11th Dec 2018, 10:49 AM
Ibaadi Jaya
Ibaadi Jaya - avatar
2 Answers
+ 7
https://code.sololearn.com/WP4ET66OwlVV/?ref=app
11th Dec 2018, 10:58 AM
Rstar
Rstar - avatar
+ 5
The reason is because the element you're trying to access isnt yet created when the code run. As you can see from Rstar example, the code need to run after the page loaded using onload listener. Other method is write the script at the bottom part of the body.
11th Dec 2018, 11:02 AM
Taste
Taste - avatar