Just create a function that will bind everything, parameterize it so that you can pass to where you want to listen to the click, which element you want to drag. Toggle and the label you want to set on the button.
function bindClick(click_tgt, rel_el, label) { $(click_tgt).click(function () { $(this).text($(this).text() == '+ ' + label ? '- ' + label : '+ ' + label); $(rel_el).slideToggle('slow').css({'display' : 'block'}); return false; }); } $('#top_menu,#commun_links,#q_links').hide(); bindClick('#top_menu_toggle', '#top_menu', 'Menu'); bindClick('#commun', '#commun_links', 'Community'); bindClick('#qnav', '#q_links', 'Quick Links');
And name it what suits you best :)
source share