tags:

views:

91

answers:

2

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?

+4  A: 

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.

BrunoLM
[Documentation](http://api.jquery.com/jQuery.noConflict/) (example 2)
Michael Mrozek
I saw that, but when I use that technique, the plugin throws an error, the main set up function i.e. simpleSlide();, becomes unrecognized.
badnaam
Could there be a loading issue..this is how I load it now..<script type="text/javascript" src="bb/js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery.simpleSlide_min.js"></script><script type="text/javascript"> var $j = jQuery.noConflict(); </script>
badnaam
when are you loading prototype?
Jon Erickson
A: 

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.

AndrewDotHay