DRY jQuery to toggle elements
I always have links that will hide something on a page. something like:
This is how I have done it in the past:
$("#rollup").click( function() { $("#new_capacity_form").slideToggle(); });
But by adding a rel value to your links, you can do it smarter
$('#rollup').click( function(){ var what = $(this).attr('rel'); $('#' + what ).slideToggle(); });
In my views, I add this link
link_to "cancel", "#", :id => 'rollup', :rel => 'new_capacity_form'
vois la! now I am able to rollup all over my site with only one line of jQuery.



