How to resolve JQuery, Prototype, and lightbox issues to make them work on same page
jQuery emerged as solution for cross platform rich media applications. A featured content gallery , image sliders are few examples of the jquery.
A fast, concise, library that simplifies how to traverse HTML documents, handle events, perform animations, and add AJAX.
Prototype provides class-style Object Oriented and AJAX, freely distributable under the terms of an MIT-style license. Prototype are used with image manipulations and galleries and slitter differ from the Jquery.
While working on few projects i need to use both of the libraries of JQuery and Prototype but normally they don’t work on the samepage due to functions clashes. Ideally jQuery library should not clash with other libraries because it have defined name-spaces with its own names and all the callback global objects are stored inside those jQuery name spaces. Beside the above facts the two different library clashed on the same page. Do you know why? It is because of the shortcut “$”, used to call jQuery.
What is the Problem?
My jQuery don’t work with Prototype?
My jQuery don’t work with lightbox?
$-function is the problem.
What is the Solutions?
To remove or modify the cause of the Problem i.e the $-function
Solution1 – Override the $-function
Override the $-function such that it will not conflict with other libraries. This could be done by calling the overriding function jQuery.noConflict() at any point in the header after jQuery script. Overriding function jQuery.noConflict() resolve the Jquery clash with other javascript libraries.
<html>
<head>
//This is sample head of your page
<script src="prototype.js"></script>
<script src="jquery.js"></script>
//This should be include at the end of the both the scripts
<script> //**Start of your patch**//
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script> //**End of your patch**//
</head>
<body></body>
</html>Solution2 – Reassign default $-function of jQuery into another shortcut function like $j
Reassign jQuery to another shortcut i.e defined another variable instead of the $-function resolve the jQuery clash with other javascript libraries. For example you can assign
<html> <head> //This is sample head of your page <script src="prototype.js"></script> <script src="jquery.js"></script> //This should be include at the end of the both the scripts //**Start of your patch which Reassign jQuery to another shortcut**//<script> var $j = jQuery.noConflict(); // Use jQuery via $j(...) $j(document).ready(function(){ $j("div").hide(); }); // Use Prototype with $(...), etc. $('someid').hide(); </script>//**End of your patch**//
</head>
<body></body>
</html>
Note: If you used lightbox or other libraries then you can use the same $-function patches to make them work on the same page. If you have any issues with the problem or your problem still not resolved then feel free to ask here.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackbackfrom your own site.
Subscribe to our FREE Rss FeedWhat's Hot
Similar Interesting Posts
- JavaScript hack
- How to fix application/x-httpd-php – Trouble in getting php to parse
- Top 10 way to speed up your website
- How to alphabetize html links into order
- How to fix IE6 PNG Transparency issues in wordpress
- Remove Ads from My Yahoo Beta
- Book Burro
- Top 10 Web Design Forums For Web Designers and Developers
- How to hide a categories posts from wordpress RSS Feeds without using any plugin
- Dont Require Email
- Top 50 Design and Web development Resources
- Your next lifesaver is Hirens Boot Cd 9.4
- Give your computer a name (broadcasting from Dynamic IP)
- How to convert batch script files to EXE files
- Top 10 HTML / CSS Resources
Tutorials On









August 23rd, 2009 at 1:35 pm
How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://is.gd/2uAGP #$-function
August 23rd, 2009 at 1:35 pm
How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://is.gd/2uAGP #$-function
September 18th, 2009 at 1:48 pm
funky pop up effect on ‘Share this’ Icons – http://bit.ly/2NwP3b
October 14th, 2009 at 2:06 pm
I implemented the solution 2. It is working fine in Firefox but not in IE. Showing operation Aborted error.
October 31st, 2009 at 5:00 pm
How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://bit.ly/1yhMth
December 9th, 2009 at 1:36 pm
http://htmlerror-info.blogspot.com/2009/12/prototypejs-in-lightbox-or-thickbox.html
January 18th, 2010 at 5:13 pm
@DaPo http://bit.ly/4Kqsux Google est ton ami :p
February 5th, 2010 at 5:33 pm
Thank you soooooooooooooooooo much!!!!!!!! works like a charm for me!!! ^_^