1

Possible Duplicate:
Can I use multiple versions of jQuery on the same page?

I add some new javascript code in a website that is using 1.2.4. The code I add now need 1.8.2 version.

So, this is the code I have :

var thisPageUsingOtherJSLibrary = false;

if (typeof jQuery == 'undefined' || jQuery.fn.jquery !== '1.8.2') {
    if (typeof $ == 'function') {
        thisPageUsingOtherJSLibrary = true;
    }

    function getScript(url, success) {
        var script = document.createElement('script');
        script.src = url;

        var head = document.getElementsByTagName('head')[0];

        done = false;
        script.onload = script.onreadystatechange = function () {
            if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
                done = true;
                success();
                script.onload = script.onreadystatechange = null;
                head.removeChild(script);
            };
        };

        head.appendChild(script);
    };

    getScript('http://code.jquery.com/jquery-1.8.2.min.js', function () {
        if (typeof jQuery !== 'undefined') {
            if (!thisPageUsingOtherJSLibrary) {
                jQuery(document).ready(function ($) {
                    initWithNewJquery($);
                });
            } else {
                var jQuery_1_8_2 = $.noConflict(true);
                jQuery_1_8_2(document).ready(function ($) {
                    initWithNewJquery($);
                });
            }
        }
    });

} else {
    jQuery(document).ready(function ($) {
        initWithNewJquery($);
    });
}

function initWithNewJquery($){

}

what I need is : using the old jquery for the website where I add the code. Using the new jquery for my new functions/handler (that will be added inside function initWithNewJquery($)).

For some reasons, I think the code I wrote is wrong, also because I get this error :

TypeError: a.livequery is not a function

So, how should I use correctly noConflict() here?

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507
  • @RoryMcCrossan : that doesnt help! I can't manage the other variables of the old version of jquery with jQuery_1_2_4, for example. The old code with old version must use $, my new code must use a new variable (like jQuery_1_8_2). Is it more clear now? – markzzz Oct 04 '12 at 09:37
  • Then swap the order of the scripts around... ? – Rory McCrossan Oct 04 '12 at 09:39
  • I can't! New version will be added later (I'm in a portlet, the code is added in the middle of the page) – markzzz Oct 04 '12 at 09:48
  • Anyway : adding `var jQuery_1_8_2 = $.noConflict(true);` I should resolve, right? Other libraries that use $ is my old jquery. jQuery_1_8_2 is the new one... – markzzz Oct 04 '12 at 09:51

0 Answers0