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

21st Jan 2021, 6:54 AM
Sajid Ali
Sajid Ali - avatar
2 Respostas
+ 2
Sajid Ali Because box is called before loading the contents. Put that line inside onload function.
21st Jan 2021, 7:03 AM
A͢J
A͢J - avatar
+ 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
21st Jan 2021, 7:04 AM
Abhay
Abhay - avatar