jQuery.noConflict() breaks plugin
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.
精彩评论