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 is 1 comment 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.

Write a comment: