0

I have a Cisco JS library designed to work using JQuery 1.4.2 and I'm using latest 2.X version of JQuery on the UI page I'm developing.

Cisco Library

I'm using Jabberwerx.js file from the above library link.

The library works fine if the JQuery loaded is of 1.4 but fails to work with later versions of JQuery. If I use old version of Jquery my UI based on bootstrap doesn't work. I tried to use noConflict() but then I can not edit the entire library which is very huge. There are lots of webservice calls and functions on the library so upgrading it is very painstaking.

Is it possible to use a particular version of JQuery on this JS file and the rest of the application can use the latest version of JQuery?

The library has this code on it. Can we change this to make it work using old version of JQ.

(function(window)
{   var jQuery=function(selector,context)
    {
        return new jQuery.fn.init(selector,context);
    },
    _jQuery=window.jQuery,
    _$=window.$,
}

I'm not looking at using different versions of JQuery on the same page but I'm trying to limit the usage of one version of JQuery to one of the JS files.

Chandra Eskay
  • 2,163
  • 9
  • 38
  • 58
  • 1
    `$.noConflict()` is your only hope. Or you can degrade your code to work with `1.4.2` version of JS (it will be pain after 2.x version :) ). – Justinas Nov 30 '15 at 09:40
  • 1
    Possible duplicate of [Can I use multiple versions of jQuery on the same page?](http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) – Aditya Singh Nov 30 '15 at 11:04

2 Answers2

1

When you use different version of jquery then your code conflicts. So there may appear obvious errors.

To fix it, you need to use $.noConflict() passing a boolean parameter true.

jQuery.noConflict(true);
//removes jquery itself and allows you to work with different version of jquery

Example:

<script src="jquery-version-1.0"></script>
<script>//code for v-1</script>
<script>jQuery.noConflict(true);//remove jquery</script>
<script src="jquery-version-2.0"></script><!--use another version-->
<script>//code for v-2</script>
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • That will not solve your problem always. you have to add jquery's based on the priorities sometimes. I mean include version2 first,then version 1 like that. Take help of browser tools what all red errors means(right down corner). you can also assign $ for version1 ,$$ for version 2 and so on, which will also help to reduce the dependency. default, $ takes the whichever jQuery version loads first. – Dirty Developer Nov 30 '15 at 10:18
1

In addition to what Bhojendra Nepal's answer, You can also check the version of jQuery through the following Code :

var jq_version = $().jquery;
    console.log(jq_version);
    /* gives the version number like 1.7.1. So may be you can write an if condition around the version number. For e.g :*/
    if(jq_version == '1.7.1'){
        //do something for ver 1.7.1
    }

There are even more ways to Check the version of jQuery. But I'm not sure if that would help much with the CISCO library you are using.

Varg
  • 56
  • 4
  • never post an answer that relies only on the link. If that page goes offline, changes,etc. then the answer becomes void... Always reply an answer with an way to fix the problem. – Bonatti Nov 30 '15 at 10:35