Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery/Javascript conflicts?

I just implemented a multi-language mod onto my website.

Problem is that there seems to be a conflict between the javascript files from the language mod and the javascript files that already were on the page.

<!-- language files here -->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/translationEngine.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script> 
<script type="text/javascript" src="js/jquery.translate-1.3.9.min.js"></script>
<script>var browserlang = 'en';</script> 


<!-- Javascript -->

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.pngFix.pack.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/concept.js"></script>

js/jquery-1.3.2.min.js is what makes the 3 image slider on the homepage work, but... it seems to also be interfering with the functions of the translator.

If u remove js/jquery-1.3.2.min.js from the page, the translator works fine, but the slider no longer works.

removing js/jquery-1.4.2.min.js from the page doesnt make the translator work either, in fact it seems to cause more errors in the back.

Can someone guide me in the right direction that would allow me to make the language translator and image slider both work?

http://filefx.com

Thanks :)

like image 762
jiexi Avatar asked Sep 15 '26 16:09

jiexi


2 Answers

The short version is to remove this:

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

And update your plugins, there are likely 1.4.x versions out there for each of them. By including jQuery a second time, like you are currently, it'll wipe out plugins and cause all sorts of issues...the first step is removing the second (hopefully the older) instance.

Edit: Here's an updated version of jFlow called jFlow plus that works with 1.4.2.

like image 131
Nick Craver Avatar answered Sep 17 '26 05:09

Nick Craver


Check out the jQuery noConflict function. This function tells jQuery to relinquish it's control over the $ variable. This way, other libraries can use it.

The online docs give a pretty good guide as to how to use this function. It saved me a few times.

Example from the online docs:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

Basically, once you call noConflict, you can still use jQuery, just use it using the jQuery variable name instead of $.

Hope this helps!

like image 24
David Hoerster Avatar answered Sep 17 '26 05:09

David Hoerster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!