Make jQuery work on the same page with Mootools and or Prototype

Some conflicts appear when using jQuery javascript library with Motools or Prototype on the same page. A workaround is using noConflict mode for jQuery.

Follow this steps:

1. Download the latest version of jQuery

2. Download jQuery compat

3. Open jquery.js, go to the end of the file and add this line jQuery.noConflict();

4. With jquery.js opened, open jquery.compat-1.0.js copy all it's content and paste-it after jQuery.noConflict(); line in jquery.js.

5. Find this lines and comment or delete them them:

jQuery.fn._filter = jQuery.fn.filter;
jQuery.fn.filter = function(arr){
  return this._filter( arr.constructor == Array ? arr.join(",") : arr );
};

6. Open all .js files that use jQuery library and add as the first line (function($){ and as the last line })(jQuery);

(function($){
content of the .js file
})(jQuery);

That's it.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.