Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.noConflict() breaks plugin

Tags:

jquery

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?

like image 450
badnaam Avatar asked Jan 25 '26 21:01

badnaam


2 Answers

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.

like image 84
BrunoLM Avatar answered Jan 27 '26 10:01

BrunoLM


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.

like image 37
a7drew Avatar answered Jan 27 '26 11:01

a7drew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!