Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent $.getScript from executing the document.ready content?

I want to call a function that's in another JavaScript file.

function foo(){
    //before $.getScript
    $.getScript('otherScript.js', function() { 
        otherFoo();
    });
    //after $.getScript
}

But this will execute the whole $(document).ready() part of otherScript.js before calling otherFoo() function. How can I prevent $(document).ready() from being called and call only otherFoo() function?

like image 509
reika Avatar asked Jun 21 '26 02:06

reika


1 Answers

You can't do this.

It will run the whole file. If you don't want anything to run then put everything in otherScript.js in functions.

What you wish to do is not possible without writing a seperate parser.

like image 50
Toby Allen Avatar answered Jun 22 '26 14:06

Toby Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!