-2

I want use two different jquery version on one page it is my codes:

    <!----- mobile menu Starts ----->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style/mobile_menu.css">
    <script type="text/javascript">
        var jQuery_1_11_0 = $.noConflict(true);
    </script>
    <!----- mobile menu  Ended ----->
    <!------ The Post slide starts ------>
    <link rel="stylesheet" type="text/css" href="./style/post_slide_style.css">
    <script src="js/jquery.v1.5.1.min.js"></script>
    <script type="text/javascript">
        var jQuery_1_5_1 = $.noConflict(true);
    </script>
    <script type="text/javascript" src="./js/jquery.colorbox.js"></script>
    <script>
        jQuery_1_5_1(document).ready(function(){
         jQuery_1_5_1("a.gallery").colorbox({rel:'gallery'});
         jQuery_1_5_1("a.dbox").colorbox({iframe:true, width:"480", height:"580"});
         });
    </script>
    <!------ The Post slide Ended ------->

The Mobile Menu is work but The Post slide isn't work thanks for helping

Muhamad Kwexa
  • 23
  • 1
  • 4
  • 11
    The real question is **Why do you need 2 JQuery versions** ? – Weedoze Nov 17 '16 at 14:19
  • How does post_slide2.js access jQuery. Is it with `$`? In that case it's actually accessing v1.11.0, which I don't think is what you want. – laurent Nov 17 '16 at 14:23
  • oh sorry post_slide2.js = jquery.colorbox.js – Muhamad Kwexa Nov 17 '16 at 14:26
  • @this.lau_ it would actually not have access to jQuery at all (*not `$` nor `jQuery` of any version*). – Gabriele Petrioli Nov 17 '16 at 14:26
  • @MuhamadKwexa which version do you want the ***jquery.colorbox.js*** to use? – Gabriele Petrioli Nov 17 '16 at 14:27
  • @GabyakaG.Petrioli I don't know because I downloaded from a tutorial its the link https://www.mediafire.com/?6fxxudbfsocgg0y – Muhamad Kwexa Nov 17 '16 at 14:34
  • Please first think what do you actually want to do - don't download scripts from hosting services like mediafire, but use library that is maintained - http://www.jacklmoore.com/colorbox/ for example, which supports jquery.1.3.2+, so will work with 1.11 – eithed Nov 17 '16 at 14:43

2 Answers2

1

You should not have 2 different JQuery Versions.

You should use the latest version of JQuery. If you need to support some legacy JQuery API, you addiotnaly need to use the jQuery Migrate Plugin

From the documentation:

We have created the jQuery Migrate plugin to simplify the transition from older versions of jQuery. The plugin restores deprecated features and behaviors so that older code will still run properly on newer versions of jQuery. Use the uncompressed development version to diagnose compatibility issues, it will generate warnings on the console that you can use to identify and fix problems. Use the compressed production version to simply fix compatibility issues without generating console warnings.

There are two versions of Migrate.

The first will help you update your pre-1.9 jQuery code to jQuery 1.9 up to 3.0. You can get that version here:

The second version helps you update code to run on jQuery 3.0 or higher, once you have used Migrate 1.x and upgraded to jQuery 1.9 or higher:

Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
0

The main problem is that you are passing true to both noConflict calls.

jQuery.noConflict( [removeAll ] )
removeAll
Type: Boolean
A Boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself).

So after those calls you code has not access to $ nor jQuery so you should be getting some errors in your console.

If you want to use the second version of jquery then remove the true from that noConflict call.


In general, though, it is a bad sign when you must use two versions of jQuery in the same page.

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317