Prototype and jQuery conflict resolution

This article will guide you how to solve the conflict between jQuery and Prototype to simultaneously, in order to use both libraries on the same web page.


Sampled by © JavaScriptBank.com

I experienced this conflict quite recently when I was working on WordPress Featured Articles Plugin. Normally jQuery.noConflict() comes to the rescue but not in my case. And the reason being - prototype was already interacting and was included at the top, so it was already using the $ variable.

This conflict causes the creation of the jQuery object to fail.

 

All the following errors are related to this conflict and you might get one or all of the following while using Prototype (Scriptaculous) and jQuery -

jQuery is not defined

$ is not a function

$ is not defined $(document).ready(function(){

Component returned failure code: 0×80040111 JavaScript error

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMViewCSS.getComputedStyle]" nsresult: "0×80004005 (NS_ERROR_FAILURE)"

What can we do to fix this?

You can try moving the jQuery.js to top and than use jQuery.noConflict().

If that is not an option you can do the following -

IMPORTANT - Do not use [REPLACE ALL]

  • Edit prototype.js - find where it defines function $() and change the name to function $$$()
  • Still in prototype.js, carefully replace each occurrence of $(... ) with $$$(... ), but don't touch anything which says $$(... )
  • Edit each of the other *.js files (e.g. effects.js) and carefully replace each occurrence of $(... ) with $$$(... ), but don't touch anything which says $$(... ).
  • That is it.

And just in case you have trouble doing the above, Following links point to already edited prototype.js and effects.js. Please remember all the references to these files must start with $$$ instead of $.

Download - Prototype.js

Download - Effects.js

Hopefully this article will help some of our fellow coders and save them some time and frustration. Happy Coding guys :)

Language
Translate this page to English Translate this page to French Translate this page to Vietnamese

Recent articles
Vue.js developers: hire them, use them and get ahead of the competition
3 Reasons Why Java is so Popular
Migrate to Angular: why and how you should do it
The Possible Working Methods of Python Ideology
JavaScript Research Paper: 6 Writing Tips to Craft a Masterpiece
Learning How to Make Use of New Marketing Trends
5 Important Elements of an E-commerce Website
How To Create A Successful Prototype For Your PCB
WordPress Landing Page Conversion Essentials to Convert More
Lifeasapa and Neurosphere


Top view articles
Top 10 Beautiful Christmas Countdown Timers
65 Free JavaScript Photo Gallery Solutions
Best Free Linux Web Programming Editors
Top 50 Most Addictive and Popular Facebook mini games
Top 10 Free Web Chat box Plug-ins and Add-ons
Top 10 Best JavaScript eBooks that Beginners should Learn
50+ Beautiful Resources of HTML Form using CSS and JavaScript
The Ultimate JavaScript Tutorial in Web Design
10 Great JavaScript Frameworks for Faster JavaScript Application Development
HTML5 Web Workers Multithreading in JavaScript


Free JavaScript Tutorials & Articles
at www.JavaScriptBank.com