Search code examples
jqueryjquery-pluginsgetscript

Can getscript run imported scripts in jquery noconflict?


Say I am running a version of jQuery in no conflict like this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script type="text/javascript">var jQuery191 = $.noConflict(true);</script>

And I had an external .js file that should be run with the no conflict version jQuery191 and included the jQuery object of (jQuery) at the bottom of the script.

If I included the .js file in getScript() and ran it with the no conflict jQuery object:

(function (jQuery) {
    $.getScript("js.js");
})(window.jQuery191)

Would the script be run with jQuery191 or with the original jQuery? Or is this logic just dumb.


Solution

  • getScript will just load the script and add it to the page, it won't affect the script's behavior at all. If the script accesses jQuery by it's global name, then it won't find it (due to the noConflict being called), and won't be able to run correctly.

    If you can, I'd suggest including the script before calling noConflict, otherwise you'll have to modify the script to look for jQuery in the place you put it (jQuery191).