0

Loading problem with the playground

You can't use window.onload to get some values(eg. let x = document.getElementById("id"); )and use it later on. Since its local variable. You can't even make the script load at the end since its not external. I needed to get some divs and use them later but it was showing error since the html didn't load. Is there any way to solve this problem?

9th Aug 2018, 1:24 PM
Akib
Akib - avatar
4 Answers
+ 3
declare you variable globally var x; window.onload =function(){ x = document.getElementById("test"); x.style.color = "red"; }
9th Aug 2018, 5:35 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
Didn’t load? onload is not executed?
9th Aug 2018, 3:50 PM
Toni Isotalo
Toni Isotalo - avatar
9th Aug 2018, 5:06 PM
Akib
Akib - avatar
0
😂😂I'm so stupid. Thanks Toni Isotalo.
10th Aug 2018, 12:38 AM
Akib
Akib - avatar