-2

I am using 2 JQuery versions on my website, but there is a problem with loading both versions at the same time. If one runs, then other one can't run. I am using Date Time picker and High charts. I have already searched for code to handle JQuery conflicts, but I don't understand them. I am new to JQuery.

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>

These are used for the date time picker.

<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"> </script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>

And these is used for the high charts. Please tell me a simple way that I can load both at the same time.

Ash Wilson
  • 22,820
  • 3
  • 34
  • 45

4 Answers4

1

As far as I know, you don't need to load the JQuery library twice.

//load JQuery Library
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
//load Jquery UI Library
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
//load the code for highcharts
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
//load the css for JQuery UI
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all">
C_B
  • 2,620
  • 3
  • 23
  • 45
1

I think this is fairly unwise.

If you have a dependency that won't use a higher version of jquery then that dependency limits you to that particular jquery version.

My advice would be that you can only ever have one jquery instance loaded at a time. You could try noConflict(), but this is likely to cause trouble with any dependent libraries that may not implement this perfectly.

Captain John
  • 1,859
  • 2
  • 16
  • 30
0

Well this is not tested but you could probably make use of the noConflict and setting them to diffrent shortnames

something like

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"> $jq1=jQuery.noConflict (); </script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript"> $jq2=jQuery.noConflict (); </script>

Then use the first one as $jq1('whaeverselector')...

Iesus Sonesson
  • 854
  • 6
  • 12
0

Yes, it's doable due to jQuery's noconflict mode.

http://blog.nemikor.com/2009/10/03/using-multiple-versions-of-jquery/

<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://example.com/jquery-1.1.3.js"></script>
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>

<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://example.com/jquery-1.3.2.js"></script>
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>

Then, instead of

  $('#selector').function(); 

you'd do

 jQuery_1_3_2('#selector').function(); 

or

jQuery_1_1_3('#selector').function();.
saun4frsh
  • 383
  • 1
  • 4
  • 21