开发者

jQuery.noConflict() breaks plugin

开发者 https://www.devze.com 2023-01-07 02:51 出处:网络
开发者_运维百科I use both Prototype and jQuery in my rails app. To resolve the $ conflict I do the following:
开发者_运维百科

I use both Prototype and jQuery in my rails app. To resolve the $ conflict I do the following:

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

This works mostly fine, but I am trying to use a plugin that does not like it and throws a $ is not a function type error.

What can I do to fix it?


Try the following

(function ($){
    /* plugin code */
})(jQuery);

This is creating a function and executing it right away passing jQuery as a param named $. Meaning $ would work as jQuery only inside this scope.

Since the plugin have internal methods that uses $ the best would be to ask for a fix, or fix by yourself changing any $ that is a problem for jQuery.


Uhg. Some functions for simpleslide use a jquery wrapping technique to protect its internal use of $ and other functions do not.

It's only a couple of top level functions with the exposure problem (as near as I can tell), so you could add the protective wrappers yourself and/or ask the author for a fix.

0

精彩评论

暂无评论...
验证码 换一张
取 消