two version of Jquery conflict

∥☆過路亽.° 提交于 2019-12-10 10:04:16

问题


Further, I noticed that my site is loading two version of jquery

<script type="text/javascript" src="http://www.nyimexec.com/wp-includes/js/jquery/jquery.js?ver=1.7.2"></script>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js?ver=1.8.21"></script>

I have disabled most my plugins, except some menu navigator, and cannot identify where the jquery from google cdn is located. Which plugin if any? or in which file?

Can you help me

  • idenfity where it is coming from (even general guide of where to look, or how to search)
  • how to resolve that, essentially how to delete the jquery from google cdn.

I've been reading about a non-conflict mode but, don't know where to add the no conflict command when i cannot locate the jquery google cdn.

I am asking because I have a feeling it is causing my tabs not to work. here is a page with the tabs not working http://goo.gl/umIYu

-- I realized that the first script is not same as second. However, Jquery ui from google cdn is in conflict with jqueryui used by my theme (don't know how to locate that and paste here)


回答1:


Though there is no problem in your scripts but you still may want to try this

var k=jQuery.noConflict();

and replace the $ with k in the new JS you are writing like this

j(document).ready(function(){
     alert('hey I am not conflicting with any other jquery script');
});

EDIT

Add the var k=jQuery.noConflict(); on the top of your javascript and replace all your $ in your JS with j.. j is nothing but a new jQuery object which is created by us and performs all functions that are performed by $ but does not conflict with any other jQuery file on the page..

Example: If you have

$(document).ready(function(){
     $('#selector').click(function(){
          alert('Hi');
     });
});

it should be written like

j(document).ready(function(){
     j('#selector').click(function(){
          alert('Hi');
     });
});

after using the noConflict..

Edit-2:

One of the other possible reason for your tabs not working can be the older version of jquery you are using

You are using a higher version of jQuery UI and a lower version of jQuery, Which can be a possible reason.. Try replacing the follwing scripts

<script type="text/javascript" src="http://www.nyimexec.com/wp-includes/js/jquery/jquery.js?ver=1.7.2"></script>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js?ver=1.8.21"></script>

with

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>


<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>

Hope it helps...




回答2:


You should list the versions from largest to smallest.

Example:

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.0/jquery-ui.min.js?ver=1.0'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.0.1/jquery-ui.min.js?ver=1.0.1'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.2.1/jquery-ui.min.js?ver=1.2.1'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.3.0/jquery-ui.min.js?ver=1.3.0'></script>

And so on...




回答3:


The two libraries are not same. One is the jQuery and other is the jQueryUI library which can be used together without any problem.



来源:https://stackoverflow.com/questions/15595403/two-version-of-jquery-conflict

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!