How to use different version of JQuery on a JS file?

前端 未结 2 1737
野趣味
野趣味 2020-12-12 07:01

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

相关标签:
2条回答
  • 2020-12-12 07:34

    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>
    
    0 讨论(0)
  • 2020-12-12 07:48

    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.

    0 讨论(0)
提交回复
热议问题