Skip to content Skip to sidebar Skip to footer

If You Include 2 Version Of Jquery In A Page How Do You Restrict A Plugin To Just One Of Them?

So this question isn't as crazy as it might sound at first. I'm developing a piece of javascript code to drop into my client's pages. What I'm worried about is if they are using

Solution 1:

There is a trick you could use. If your version of jQuery is second which loads, you will need first move to safety theirs version before you load it, something like this

<scripttype="text/javascript">
    (function($){
       var theirs_jquery = $;
    })(jQuery);
</script>

Then add your jQuery version script include tag

<scriptsrc="link/to/my/jquery.js"></script><!-- add your plugins --><scriptsrc="link/to/my/jquery/plugins/plugin1.js"></script><scriptsrc="link/to/my/jquery/plugins/plugin2.js"></script>

then add another script block with folowing

<scripttype="text/javascript">
(function(){
    var $$ = jQuery; // this is your shortcutvar $ = theirs_jquery; // put back their version
})(jQuery);
</script>

after this you can access your jquery version with $$ shortcut

Solution 2:

You could use

(function($) {        

})(dom);

To wrap you calls.

This maps dom to $ for just the code within replacing any external $ definition.

But I am not sure if this works with 2 different jQuery, maybe jQuery cannot coexist with other jQuery versions.

Post a Comment for "If You Include 2 Version Of Jquery In A Page How Do You Restrict A Plugin To Just One Of Them?"