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
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
+ 1
https://code.sololearn.com/WqDu1sP6ExKZ/?ref=app
+ 1
<StraMa/Design> Its ok
- 1
KrOW what do you think about it? 👍
https://code.sololearn.com/WxQWCd0OPPv6/?ref=app