7

Is it possible to handle conflicts between 2 versions of jQuery loaded in the same page? Assume that these lines of code:

<script type="text/javascript" src="jquery-1.1.3.js"></script>
<script type="text/javascript" src="jquery-1.4.2.js"></script>

<script type="text/javascript" src="thisFileUsesFirstJquery.js"></script>
<script type="text/javascript" src="thisFileUsesSecondJquery.js"></script> 

I don't use inline java script code. In my situation, my java script code take place on external file. My question is: How should I use noConflict() method that prevent from conflicting between them.

Misagh Aghakhani
  • 1,023
  • 2
  • 13
  • 29
  • i think you must declare a noConflict variable instantly after each jQuery script tag in inline script tag. – user197508 Nov 11 '12 at 12:43

1 Answers1

20

yes you can do it like this:

  <script type="text/javascript" src="jquery-1.1.3.js"></script>
  <script> $113 = jQuery.noConflict();</script>
  <script type="text/javascript" src="jquery-1.4.2.js"></script>

and then use either $113 or $ in your code

Kirill Ivlev
  • 12,310
  • 5
  • 27
  • 31
  • Thank you Kirill I,m actually using wordpress and one jquery file is in the header.php and another on is in the another php file.When I browse my website some of the act in my site dose not work properly. – Misagh Aghakhani Nov 11 '12 at 13:15
  • 1
    @MisaghAghakhani you need to change all `document.ready` in existing code prior to adding 1.4 from `$(document).ready(function(){/* code*/}` to `$113(document).ready(function($){/* code*/}`. You will still be able to use `$` inside that wrapper...or upgrade all previous code which likely has a lof `@` used in selectors which is a protocol that was deprecated – charlietfl Nov 11 '12 at 13:31