0
When (and why) js scripts in SoloLearn tutorials run?
In the SoloLearn tutorials and in the coding playground, it seems that the JS code written in the JS tab is loaded in the head element. However, there is never any reference to the script code, no line to include it or anything.. The reason I am asking is that I'm just starting the jQuery course, and I wanted to load the library after the page loads by moving the jQuery library script line to the end, but then the JS brakes. Is this because it tries to run the JS in <head> before the jQuery is added?
2 Answers
+ 2
Yes, the code in the css and js tabs is injected into the html page in the head of the page behind the scenes. In order to get the code in the JS tab to run after the page loads, you can wrap the code in a window.onload function or in the case of jQuery document.ready. You can also do a standard link to a js file at the bottom of the body that is located elsewhere via a url, such as a cdn.
0
@ChaoticDawg thanks, that explains alot. I think it's a bit strange though, it would be nice if thinks wew as "in real life"..