Is this it, or do you have something shorter? $('#nav > li').each( function () { var $this = $(this); $this.bind('mouseenter mouseleave', function() { $this.toggleClass('hover') }); });
I thought hover would work, but it only does the mouseenter with one parameter, instead of doing the same function for both enter and leave. $('#nav > li').each( function () { var $this = $(this); $this.hover(function() { $this.toggleClass('hover') }); // only mouseover }); which could be abstracted to a hoverClass plugin $('#nav > li').hoverClass('hover');