0

Issue with HTML running after JS

I'm working on a program and I had my HTML and JS on separate tabs but then I ran it, it showed me this error message: Uncaught TypeError: Cannot set property 'innerText' of null. So I went to Stackoverflow, and there said because HTML has to run first, so in the HTML tab, I made the <script> tags and put my JS their and worked. But shouldn't it work inside the JS tab too, because I would like for it to be external JS.

19th Mar 2020, 12:13 AM
Danial Azadpour
Danial Azadpour - avatar
3 Answers
+ 2
Put your JS in the following function. window.onload = ()=> { JS here... }
19th Mar 2020, 12:50 AM
yochanan sheinberger
yochanan sheinberger - avatar
+ 1
Thanks that fixed the problem!
19th Mar 2020, 2:02 AM
Danial Azadpour
Danial Azadpour - avatar