2

I realize there are already various answers out there to questions about using multiple jquery versions on a page, but I have not been able to figure out how to apply them.

On my page I have two .js files - one for operating a collapsible menu, and the second for a thickbox gallery. The collapsible menu stopped working when I added the gallery. When I tried to use the no conflict solution from the link below, the menu worked but the gallery images would no longer load.

http://api.jquery.com/jQuery.noConflict/

Any ideas of what I'm doing wrong? Do I need to add things to both the .html file and the .js files?

code:

<script type="text/javascript" src="../../01 Main/includes/jquery-1.6.min.js"></script>
<script type="text/javascript" src="../../01 Main/includes/main.js"></script>
<script type="text/javascript">
<div id="log">
  <h3>Before $.noConflict(true)</h3>
</div>
</script>

<script type="text/javascript" src="../scripts/jquery-latest.js"></script>
<script type="text/javascript" src="../scripts/thickbox.js"></script>
<script type="text/javascript">
var $log = $( "#log" );

$log.append( "2nd loaded jQuery version ($): " + $.fn.jquery + "<br>" );

jq16min = jQuery.noConflict(true);

$log.append( "<h3>After $.noConflict(true)</h3>" );
$log.append( "1st loaded jQuery version ($): " + $.fn.jquery + "<br>" );
$log.append( "2nd loaded jQuery version (jqlatest): " + jqlatest.fn.jquery + "<br>" );
</script>

also tried:

<script type="text/javascript" src="../../01 Main/includes/jquery-1.6.min.js"></script>
<script type="text/javascript" src="../../01 Main/includes/main.js"></script>
<script type="text/javascript">
var jQuery_1_6_min = $.noConflict(true);
</script>

<script type="text/javascript" src="../scripts/jquery-latest.js"></script>
<script type="text/javascript" src="../scripts/thickbox.js"></script>
<script type="text/javascript">
var jQuery_latest = $.noConflict(true);
</script>
4
  • What versions of jQuery are you using, and can you post your code? Also i havent really seen thickbox used in years. If thats the script witht he dep. on an older version i would switch to something else that can use a more modern version (>=1.8.x). Commented Feb 28, 2013 at 3:34
  • It sounds like your using two jQuery plugins and they conflict with each other. jQuery.noConflict is not going to help with that. To see whats happening we'll need some code.
    – Jesse Lee
    Commented Feb 28, 2013 at 3:34
  • possible duplicate: stackoverflow.com/questions/1566595/…
    – Mortalus
    Commented Feb 28, 2013 at 3:52
  • @prodigitalson, I'm using jquery-1.6.min and jquery-latest, what would you recommend for a more updated version of thickbox?
    – Apelavin
    Commented Mar 2, 2013 at 23:38

2 Answers 2

4

it doesn't seem smart at all to use multiple versions of jquery but if you must, you could assign one of the versions to another global variable ie link to the first versions

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
window._$ = jQuery; 

then load the next version;

(function(){
  var newscript = document.createElement('script');
     newscript.type = 'text/javascript';
     newscript.async = true;
     newscript.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js';
  (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript);
})();
0
3

it is a possible duplicate to : Can I use multiple versions of jQuery on the same page?

ins short his answer:

<!-- 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>

Had to go through the same thing :)

2
  • Hmm, I tried doing this in the html file, but then neither script worked. Do I need to simultaneously rewrite something in the plug-in files?
    – Apelavin
    Commented Mar 2, 2013 at 23:58
  • There might be some other problem please post your code in your question as an update ..
    – Mortalus
    Commented Mar 3, 2013 at 3:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.