2 Jun 2020

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();

Nilambar

PHP Programmer, WordPress and Laravel Developer, Freelancer and a Blogger.

View all posts by Nilambar →

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.