How to change order load of .js file on PlayCode | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to change order load of .js file on PlayCode

Scripts are loading before page is ready when I use separate .js file and gives error. It's forcing me to put all the scripts inline on .html file. How can I change loading order of files. Compare these codes https://code.sololearn.com/W84l3fCxUDdw/?ref=app https://code.sololearn.com/WyCxo6564uBU/?ref=app

13th Dec 2019, 1:02 PM
Baxtiyor Ernazarov
Baxtiyor Ernazarov - avatar
2 Answers
+ 2
You can use "window.onload" in the JS file to run JS code only after the HTML file has loaded. For instance: window.onload = function() { // Your whole code inside here. } Code example: https://code.sololearn.com/WntPX8EKXEqh/?ref=app
13th Dec 2019, 5:24 PM
Ryan
Ryan - avatar
+ 1
Thank you
15th Dec 2019, 4:39 PM
Baxtiyor Ernazarov
Baxtiyor Ernazarov - avatar