How to track full the download script to jQuery?

Hello!

There is a script:

<script id="myscript" src="http://site.ru/script.js"></script>


Is initializing this script:

$('.element').initScript();

How to jQuery wait until it loads the main script and then start the initialization script?

While doing so:

jQuery( "#myscript" ).load( "http://site.ru/script.js", {limit: 25}, function() {
$('.element').initScript();
});


But, unfortunately, it then works, then fails... How can this be implemented?

UPD: anyway, here's the solution of this particular question:

/* Wait until fully loaded script
 * and only after it was fully downloaded, activate it */
$.getScript("http://site.ru/script.js", function() {
$('.element').initScript();
});


Concrete solution.
July 2nd 19 at 13:13
2 answers
July 2nd 19 at 13:15
the <script>
$(document).ready(function () {
$('.element').initScript();
});
</script>
It doesn't work for some unknown reason. If I put the delay in the execution of the script on a couple of seconds - is triggered. But this is not right? That's why I asked how to track the download script? - Johnathan.Nader44 commented on July 2nd 19 at 13:18
: Debug in your hands! - Alison.Bail commented on July 2nd 19 at 13:21
July 2nd 19 at 13:17
or a shorter version

$(function(){
//ready
});

Find more questions by tags jQuery