Run javascript function on script load

I am using jQuery. I keep all my function definitions wrapped in the $ (document) .ready event in application.js. I have a function from which I would like to call somewhere in the body of the page I'm working on.

I was wondering if there is any alternative to the .ready event, which will work with script loading. Ideally, I would like to do something like: $ ('application.js'). Ready (call function);

In the jQuery documentation, he only mentions the call to $ (document) .ready, but I was wondering if this could be changed or is there some simple javascript alternative.

+3
source share
2 answers

, $.getScript. jQuery JavaScript HTTP- GET . , script.

$.getScript('foo.js', function() {
 alert('foo.js was loaded, do something cool now');
});
+5

, , javascript.

+1

Source: https://habr.com/ru/post/1737355/


All Articles