jQuery: Javascript Library conflicts

15/02/2009

Sometimes, jQuery and other libraries must be used at the same time during a webpage development. The problem starts when both libraries(like prototype) use the same annotation e.g. ‘$(document).ready’. One of the two libraries is expected not to work at the same time. It is very easy to get over this. You just have to put something like this into your code:

<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript"><!--
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
// --></script>

Instead of:


<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript"><!--
$(document).ready(function(){
$("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
// --></script>

Source: Using jQuery with other libraries

There are 4 comments in this article:

  1. 21/03/2010George Nicolaou say:

    Just took a look at your blog and came across this. Your are right on the bulls-eye on this man. Thanks for the heads-up.

  2. 6/05/2014pop over to these guys say:

    e cig jQuery: Javascript Library conflicts – Yak Shaving

  3. 24/07/2014http://panda4ces.tumblr.com say:

    I absolutely love your blog and find almost all of your post’s to be
    what precisely I’m looking for. can you offer guest writers to
    write content to suit your needs? I wouldn’t mind producing a post or elaborating on many of the subjects you write with regards to here.

    Again, awesome weblog!

  4. 3/11/2014shoulder panasonic dmc say:

    Hey there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche.
    Your blog provided us beneficial information to
    work on. You have done a wonderful job!

Write a comment: