Using jQuery and Prototype together

Some time we need to use jQuery and Prototype together. To resolve the conflicting between libraries, jQuery has built-in solution. Its noConflict() method is very handy and useful.

jQuery.noConflict();
 
 // now use jQuery via jQuery(...)
 jQuery(document).ready(function(){
   //jQuery stuff
  jQuery('mydiv').hide();
 });
 
 // for Prototype use $(...)
 $('mydiv').hide();

Using jQuery everytime instead of ‘$’ seems very tedious, I think. But don’t worry, :D, there is one simple solution. You can use variable like shown below.

var $j = jQuery.noConflict();

Now you can use it as

$j('mydiv').hide();

Leave a Reply

Your email address will not be published. Required fields are marked *