简体   繁体   中英

how to properly resolve jquery conflict

I previously had a problem with jquery conflicting with jquery in the index page of a document and the jquery in the following function

    (function (window, document) {

...jquery code not necessary and far to long

})(window, document);

I have tried resolving Jquery conflict with the following code

     var jQuery132 = $.noConflict(true);
    (function (window, document) {

    .....

})(jQuery132)(window, document);

however this doesn't work for resolving the conflict and the function fails.I think it has something to do with the following part

})(jQuery132)(window, document);

How do use jquery noConflict with this type of function? Thanks

It should be something like this:

jQuery.noConflict();

(function (window, document, $) {

   ...

})(window, document, jQuery);

With jQuery being passed as a parameter to the IIFE. This effectively lets you use the $ or anything else really ( if you want to use jQuery123 go ahead ) without conflicting inside of the closure generated by the IIFE.

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