0
Why is here global variable not working in inside function ?
Var box = ....; Box varibale not working in inside function Here is my code bits : https://code.sololearn.com/W03si0HonNkF/?ref=app
2 Answers
+ 2
Sajid Ali
Because box is called before loading the contents. Put that line inside onload function.
+ 2
Actually it works, but had null value
Because u refered to an element that doesn't exist at that time. Sololearn runs the JS and then the Html part so ur tag is not initialised when u try to get it inside the box variable so to fix this put or redeclare the 'box' variable inside the window.onload function
https://code.sololearn.com/W3kiFGb8k73n/?ref=app