0

Why script run before html?

I write a small web sample. As i know script tag can be used fro external files. In external file i specify querySelector and getElementById but in both cases got null When i had done the same in html file everything shown perfectly, but only after js file run. May be i do something wrong?! Why? https://code.sololearn.com/W7kimA48WERQ/?ref=app

6th Jun 2020, 6:37 AM
george
george - avatar
5 odpowiedzi
+ 6
Your scripts are all correct it's only that Sololearn put scripts in JS tab in <head>, solution will be window.onload = function () { your scripts }
6th Jun 2020, 6:41 AM
Gordon
Gordon - avatar
0
Oooo thanks!!! I will use this trick!!!!
6th Jun 2020, 6:42 AM
george
george - avatar
0
I change it everything is work. Thank you
6th Jun 2020, 6:54 AM
george
george - avatar
0
You are welcome. Keep up the good work 💪
6th Jun 2020, 8:00 AM
Gordon
Gordon - avatar
0
Gordon i change with arrow function but on this platform not work!!! but i do it for example))) so i think such situation also ok
6th Jun 2020, 1:21 PM
george
george - avatar