 <p>Untested, but I think this does what you want.</p> <pre><code>jQuery(function () { var menus = jQuery('#menu li'); var open_menu = function open_menu() { var menu_to_open = jQuery(this); if (menu_to_open.hasClass('open')) { menu_to_open.removeClass('open'); } else { menus.removeClass('open'); menu_to_open.addClass('open'); } }; menus.click(open_menu); }); </code></pre>