Home | Contact | Videos | MediaZo

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. jquery How to resolve JQuery, Prototype, and lightbox issues to make them work on same page

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

var $j = jQuery;
 
 <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.


Honey Singh is Head of Operations & Strategic Planning at MediaZo. He has an experience of 5 years in designing, ideating/operating digital/social marketing strategies for global brands. You can also catch him on Foursquare, Twitter, Facebook , Google+ & Instagram.

29 Responses to “How to resolve JQuery, Prototype, and lightbox issues to make them work on same page”

  1. How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://is.gd/2uAGP #$-function

  2. How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://is.gd/2uAGP #$-function

  3. funky pop up effect on ‘Share this’ Icons – http://bit.ly/2NwP3b

  4. How to resolve #jQuery, #Prototype, and #lightbox issues to make them work on same page http://bit.ly/1yhMth

  5. @DaPo http://bit.ly/4Kqsux Google est ton ami :p

  6. Thank you soooooooooooooooooo much!!!!!!!! works like a charm for me!!! ^_^

  7. Great, thanks for this :)

  8. 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

  9. 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:

    <script type="text/javascript">
    jQuery.noConflict();
    var $j = jQuery;
    </script>

    or the code described in the post !
    That will resolve JQuery, prototype and lightbox issues !

  10. 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!

  11. ciscowong Says:

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

  12. ciscowong Says:

    Oops, never mind. Figured it out.

  13. 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!

  14. 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

  15. 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..

  16. Creativearc

    $(function() { $(“.lavaLamp”).lavaLamp({ fx: “backout”, speed: 700 })});

    $(document).ready(function() {
    $(‘#s3slider’).s3Slider({
    timeOut: 4000
    });
    });

  17. 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

  18. Not perplexed anymore Says:

    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($) {

  19. Not perplexed anymore Says:

    Enter $.noConflict(); after the above

  20. Muchas gracias, lo lamento no hablo(escribo) ingles. Norma

  21. 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.

  22. ‘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!

  23. 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

  24. type=”text/javascript” src=”js/prototype.js”>

  25. well its like this:

    js/prototype.js
    js/scriptaculous.js?load=effects,builder
    js/lightbox.js
    js/jquery.j

    js/jquery.galleria.pack.js

  26. <!—->
    <!—->

    <!—->

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

    });

  27. 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

  28. RFerreira Says:

    thanks a lot.. cross-browser solution 2 works for me.

Leave a Reply


× one = one