0

what's the mistake?

Hello everyone, someone can explain to me why when I assign to a variable an instruction of the tag or class does not return anything or undefined, I tried to search the web for the solution to this problem but I can not find it, can you explain something? Thank you all 👊 https://code.sololearn.com/WxQWCd0OPPv6/?ref=app

26th Feb 2019, 8:59 PM
<StraMa/Design>
<StraMa/Design> - avatar
4 Respostas
+ 3
<StraMa/Design> The problem is when js code is runned... You have to know than the code putted in js tab, will be inserted into head tag of final generated html then, when it will be executed, no DOM is loaded (eg body and his child are not loaded) then every try to access to them using document.getXXX family will have no result. For solve the problem you have to "wait" for execute your code than access to DOM, using window.onload, document.addEventListener etc... See this code https://code.sololearn.com/WlA8Fx8bl6nI/?ref=app
26th Feb 2019, 9:18 PM
KrOW
KrOW - avatar
+ 1
https://code.sololearn.com/WqDu1sP6ExKZ/?ref=app
26th Feb 2019, 9:44 PM
Solo
Solo - avatar
+ 1
27th Feb 2019, 8:29 AM
KrOW
KrOW - avatar
- 1
27th Feb 2019, 8:22 AM
<StraMa/Design>
<StraMa/Design> - avatar