简体   繁体   中英

How to remove Conflict in a jQuery plugin in a WordPress website?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM