views:

31

answers:

1

Hi,

I am using jQuery in my Rails application. I wanted to add a expand collapse text effect in my page. So I downloaded the jQuery exapander plugin and tried to use it. I am facing a weird problem.

My jQuery.js file is having this line called jQuery.noConflict(); at the end. I have to remove it to make this expand collapse effect to work. But then, when I remove it, a calendar component that I have used somewhere else in the app is not working.

Please help me out here.

Thanks.

+5  A: 

noConflict() causes jQuery to relinquish control of the $ variable. Are you using another library on the same page that also uses $? Does the calendar component use jQuery?

If your page has this:

$.noConflict();

Then from that point onward, $ is not jQuery. So:

$('#something').expander(); // won't work
jQuery('#something').expander(); // will work
$.something_from_non-jQuery_library_using_$_var(); // will work

You can also do this:

jQ = $.noConflict();

and then:

jQ('#something').expander(); // will work  
$.something_from_non-jQuery_library_using_$_var(); // will work
Ken Redler
In addition to this, you can wrap all your code that uses $ in an anonymous function and call it with jQuery as param: (function($) { $('#something').expander(); })(jQuery);
Daniel
SWEEEEEEEEEEEEEEEEEEEEET!! It solved my problem!!
Bragboy