0
Why this code showing error. In Pc not error.
4 Answers
+ 3
because code playground on web add js tab at end of html, while on app it is added in head...
if it is in head, the dom is not ready to be accessed when the script run, so getting reference to elements in page return null wich cause the error ;P
the simple fix to do (wich work in all cases) is to wrap all your js code in a function called when dom is ready:
onload = () => {
// put your js here
};
the only corner case wich could occur is if you have some variables that are required to be global: then you must declare them outside this function and initialize those who hold dom reference inside the function ^^
0
Could you resolve it.
0
Thanks buddy