javascriptjqueryruby-on-railsrubyscriptaculous

Combining Scriptaculous and jQuery in a Rails application


I've got the following situation

I want to combine the two and use my jQuery based functionality in my Rails application, but I'm worried about jQuery and Scriptaculous clashing (they both define the $() function, etc).

What is my easiest option to bring the two together? Thanks!


Solution

  • jQuery.noConflict();
    

    Then use jQuery instead of $ to refer to jQuery. e.g.,

    jQuery('div.foo').doSomething()
    

    If you need to adapt jQuery code that uses $, you can surround it with this:

    (function($) {
    ...your code here...
    })(jQuery);