最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to remove Conflict in a jQuery plugin in a WordPress website? - Stack Overflow

programmeradmin0浏览0评论

I am working on a WordPress website. I have few filters of jQuery in it and all are working fine (I initiate these plugins using):

jQuery(document).ready(function($){
  /*code here*/
});

I am also using a jQuery Plugin "filter.js" which is having conflicting issues. Even when I do not initiate this plugin (only on linking the plugin file to my page) it shows jQuery conflict and I can see in console:

Uncaught TypeError: Cannot read property 'fn' of undefined 

You can find plugin source here.

I am working on a WordPress website. I have few filters of jQuery in it and all are working fine (I initiate these plugins using):

jQuery(document).ready(function($){
  /*code here*/
});

I am also using a jQuery Plugin "filter.js" which is having conflicting issues. Even when I do not initiate this plugin (only on linking the plugin file to my page) it shows jQuery conflict and I can see in console:

Uncaught TypeError: Cannot read property 'fn' of undefined 

You can find plugin source here.

Share Improve this question edited Nov 19, 2018 at 22:27 halfer 20.3k19 gold badges109 silver badges202 bronze badges asked Jul 23, 2013 at 18:32 Imran SubhaniImran Subhani 1,1041 gold badge21 silver badges41 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Try wrapping your code like this:

(function($){

    $(document).ready(function(){
         //document ready code here
    });

})(jQuery);

Wrap your filter.js plugin with the same wrapper, ie:

(function($){

    //filter.js code here

})(jQuery);

If that's not working - make sure jQuery is included on the page.

Are you using two different versions of JQuery in the same page?

If so then use

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

just after the declaring the jQuery and replace all subsequet $ with jQuery

Hope it helps

发布评论

评论列表(0)

  1. 暂无评论