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.
Related Posts
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 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!!! ^_^
March 25th, 2010 at 11:37 pm
Great, thanks for this
April 27th, 2010 at 9:19 pm
http://www.melissaetdenis.com
Can’t seem to make it work??
Don’t know what i’m doing wrong
The website is still in developpemnt but want to resolve the sliding portion and the photo section issues
thanks
April 27th, 2010 at 11:12 pm
Hey Denis,
First of all nice design and concept for the website.
Are you planning for lightbox popup and sliding panel over this page.
Use:
jQuery.noConflict();
var $j = jQuery;
</script>
or the code described in the post !
That will resolve JQuery, prototype and lightbox issues !
May 3rd, 2010 at 1:54 am
Thanks Honey singh,
But i finally used shadowbox it works nice too, but i will try with lightbox this week again becaus i prefer lightbox again
Thanks again for the remarks on the website!
July 22nd, 2010 at 1:03 am
Tried implementing both solutions but it doesn’t seem to work. Calling jQuery and lightbox (+ prototype). The content slider and the lightbox functions are both disabled.
I must be doing something wrong… What follows below are the script calls in the section.
You can view the test site here: http://www.theadstore.com/testArea/tas/
- – - – - – - – - -
$(document).ready(function(){
$(“#featured”).tabs({fx:{opacity: “toggle”}}).tabs(“rotate”, 8000, true);
$(“#featured”).hover(
function() {
$(“#featured”).tabs(“rotate”, 0, true);
},
function() {
$(“#featured”).tabs(“rotate”, 5000, true);
}
);
});
var $j = jQuery.noConflict();
// Use jQuery via $j(…)
$j(document).ready(function(){
$j(“div”).hide();
});
// Use Prototype with $(…), etc.
$(‘someid’).hide();
July 22nd, 2010 at 1:34 am
Oops, never mind. Figured it out.
August 19th, 2010 at 6:46 am
I tried copying and pasting the code for both solutions and it did not work. Do I need to edit the ‘div’ and ‘someid’ to some code on my site? My code is similar to your example (the prototype, lightbox and jquery are linked right before I inserted your code).
Thanks for your help!
September 7th, 2010 at 1:37 pm
Hi!
I’m using prototype, lightbox and jquery at the same page so it’s definitely conflict.
so please give me some idea to resolve this.
i’m using
1. jquery carousel
2. lightbox
September 21st, 2010 at 3:56 am
Hi
This is driving me crazy. I have jquery’s lavaLamp and s3slider running. lavaLamp stopped functioning after s3slider’s script entered (s3slider working fine). Any help would be hugely appreciated!! Here’s how it looks:
Creativearc
$(function() { $(“.lavaLamp”).lavaLamp({ fx: “backout”, speed: 700 })});
$(document).ready(function() {
$(‘#s3slider’).s3Slider({
timeOut: 4000
});
});
Thanks in advance for any help..
September 21st, 2010 at 3:58 am
Creativearc
$(function() { $(“.lavaLamp”).lavaLamp({ fx: “backout”, speed: 700 })});
$(document).ready(function() {
$(‘#s3slider’).s3Slider({
timeOut: 4000
});
});
September 28th, 2010 at 5:04 pm
i hve conflict with prototype and jquery.
i hd try so many things to make it solve..unfortnatly i cant find d solution..please guide
September 28th, 2010 at 7:14 pm
This worked for me (just learning html/css)
1) Look for
2) Enter $.noConflict(); just after that
3) Look for $(function() {
4) Replace it with jQuery(document).ready(function($) {
September 28th, 2010 at 7:20 pm
Enter $.noConflict(); after the above
November 6th, 2010 at 12:23 pm
Muchas gracias, lo lamento no hablo(escribo) ingles. Norma
November 9th, 2010 at 3:28 pm
Thanks!
It Works Fine For Me!!!
If any have problems try this:
In the jquery code ……
You must :
1 .- jQuery.noConflict(); at the begining of the
2 .- Replace ALL $(whatelse) whit jQuery(whatelse)
It works for me.
Thanks again for the solution!
Obi.
December 16th, 2010 at 3:25 pm
‘null’ is blank or not an object
Linenumber: 14 (eval(nextFunct);)
My MSIE8.0 has the above error when runing the following code on a page loading jquery.js and prototype.js:
——————————–
jQuery.noConflict();
jQuery(document).ready(function() {
var HTMLbackup = jQuery(‘#DemoContainer’).html();
jQuery(‘#DemoContainer’).data(‘bkup’,HTMLbackup);
jQuery(‘#DemoOptions li a’).click(function(){
window.scrollTo(0,0);
clearInterval(siteFeature2AutoPlayInterval);
jQuery(‘#DemoContainer’).empty().html(jQuery(‘#DemoContainer’).data(‘bkup’));
var nextFunct = jQuery(this).next().text();
if(this.hash == ‘#notext’){
jQuery(‘#preFeature2 div p’).remove();
}
jQuery(‘#DemoContainer h3.title’).text(jQuery(this).text());
eval(nextFunct);
return false;
}).filter(‘:first’).click();
});
—————————————-
Need help please! And thank you!
December 25th, 2010 at 3:17 am
Hi,
I am having problems implementing the above fix and was wondering if somebody could point me in the right direction as I am not that experienced in JS.
here is my header code:
jQuery(function($) {
$(‘.gallery_demo_unstyled’).addClass(‘gallery_demo’); // adds new class name to maintain degradability
$(‘ul.gallery_demo’).galleria({
history : true, // activates the history object for bookmarking, back-button etc.
clickNext : true, // helper for making the image clickable
insert : ‘#main_image’, // the containing selector for our main image
onImage : function(image,caption,thumb) { // let’s add some image effects for demonstration purposes
// fade in the image & caption
if(! ($.browser.mozilla && navigator.appVersion.indexOf(“Win”)!=-1) ) { // FF/Win fades large images terribly slow
image.css(‘display’,'none’).fadeIn(1000);
}
caption.css(‘display’,'none’).fadeIn(1000);
// fetch the thumbnail container
var _li = thumb.parents(‘li’);
// fade out inactive thumbnail
_li.siblings().children(‘img.selected’).fadeTo(500,0.3);
// fade in active thumbnail
thumb.fadeTo(‘fast’,1).addClass(‘selected’);
// add a title for the clickable image
image.attr(‘title’,'Next image >>’);
},
onThumb : function(thumb) { // thumbnail effects goes here
// fetch the thumbnail container
var _li = thumb.parents(‘li’);
// if thumbnail is active, fade all the way.
var _fadeTo = _li.is(‘.active’) ? ’1′ : ’0.3′;
// fade in the thumbnail when finnished loading
thumb.css({display:’none’,opacity:_fadeTo}).fadeIn(1500);
// hover effects
thumb.hover(
function() { thumb.fadeTo(‘fast’,1); },
function() { _li.not(‘.active’).children(‘img’).fadeTo(‘fast’,0.3); } // don’t fade out if the parent is active
)
}
});
});
the Galleria is working fine but Lightbox is just opening the images in a new window. I have pasted your above code into the header but it just breaks Galleria!
Many thanks in anticipation.
J
December 25th, 2010 at 3:18 am
type=”text/javascript” src=”js/prototype.js”>
December 25th, 2010 at 3:21 am
well its like this:
js/prototype.js
js/scriptaculous.js?load=effects,builder
js/lightbox.js
js/jquery.j
js/jquery.galleria.pack.js
January 23rd, 2011 at 8:08 pm
<!—->
<!—->
<!—->
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery(‘.boxgrid.caption’).each(function (){
jQuery(this).mouseenter (function(){
jQuery(this).find(“.cover”).animate({top:’50px’},{queue:false,duration:160});
});
jQuery(this).mouseleave (function(){
jQuery(this).find(“.cover”).animate({top:’150px’},{queue:false,duration:160});
});
});
jQuery(“a.external”).fancybox();
});
February 8th, 2011 at 12:58 am
Hi. I am trying to use lightbox on a page that also uses various other scripts, such as “js/jquery-1.4.2.min.js”
And it seems to be lightbox’s script prototype.js that causes the problem along with the jquery.
I tried to follow the above fix, but I know so little about javascript, i couldn’t work out what you meant by for example “reassign var $j = jQuery;” How do I do that? In the jquery-1.4.2.min.js ? Or just in the page head? Or both?
I tried fix 1, just adding the “noConflict” lines in the head section of the page and that made no difference at all.
Please help!
<3
May 11th, 2011 at 11:55 pm
thanks a lot.. cross-browser solution 2 works for me.