SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    FL
    Posts
    33
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Modifying Existing Website to work with two different versions of jQuery

    Hi Guys,
    I have been working with a 3rd party vendor that has provides us ways to incorporate some widgets from their website. The widgets contain a bunch of javascript which works with jquery 1.7.2.(loaded within their code) My application still uses 1.4.2. I don't have enought time to update this right now.

    Only solution I know is to define a custom variable as $j123 = jQuery.noConflict(true);

    My question is, if I do the above, I will have to update all my javascript across the website to work with $j123 instead of the default jQuery and $. Is that correct? If so, it might be easier to update smaller functions but my main concern is how would this effect bunch of plugins that I'm using on the website, there is good about 10 of them e.g

    (function($){$.fn.jcarousel=function(..................)(jQuery);

    Would it mean that I will have find / replace all instances of $ and jQuery in the plugins?

    Please advise.

    Thanks

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    What exactly is the problem?
    Are you saying that by including jQuery 1.7.2 on your page, it is breaking some of your code written using 1.4.2?

    No conflict mode is used to have jQuery relinquish control of the $ alias, not (AFAIK) to have two versions of jQuery play nice together.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    FL
    Posts
    33
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi there,

    What exactly is the problem?
    Are you saying that by including jQuery 1.7.2 on your page, it is breaking some of your code written using 1.4.2?

    No conflict mode is used to have jQuery relinquish control of the $ alias, not (AFAIK) to have two versions of jQuery play nice together.
    Thanks for your reply.Their Jquery and scripts are loaded first in the pages. My scripts and jquery loads afterwards. They are using jquery UI as well e.g jquery UI Tabs. I get an error like JQuery does not contain a method "Tabs" caused by this line: jQuery("element id").Tabs()
    The error goes away if I remove my scrilts amd Jquery. So i beleive its looking for the tabs function which is tied to their jquery loaded first and when my jquery loads it takes control of the $ and. JQuery variable which does not have the "Tabs" function.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    It sounds to me like one version of jQuery is overwriting the other.
    Try just removing the jQuery version which is included second - you should only include the library on the page once anyway

    If this doesn't work, could you post a link to the page in question?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    FL
    Posts
    33
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    It sounds to me like one version of jQuery is overwriting the other.
    Try just removing the jQuery version which is included second - you should only include the library on the page once anyway

    If this doesn't work, could you post a link to the page in question?
    Yes that is the issue and yes if I remove my jQuery then that error goes away but then I have other errors caused by my scripts that were written for 1.4.2 (probably will upgrade next year sometime) but don't have the time right now. So I will have to load both. i apologize I won't be able to post a url for privacy reasons.

    So what is the best solution if I need to use both so all the scripts (theirs and mine) work ?

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Without seeing the code, it's basically impossible to say.
    Sorry

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    BTW, loading both is very counter productive as they will overwrite each other and cause errors.
    The browser cannot distinguish between versions of jQuery.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,837
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can only use one version of jQuery per web page.

    The only solution if you have scripts that require different versions is to put them on different web pages.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    This is true, but I'm still struggling to think of something that broke badly between 1.4 and 1.7
    Chances are if the OP showed us their code, we could help get it working.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •