ak85
ak85

Reputation: 4264

Jquery - A better way to deal with hover

I have a list which only shows the top level by default. When you hover it shows the sub menu items. This works as intended however it always leaves one menu open because the on class remains on the last item hovered on. I feel like there must be a better way to do this but other examples I have looked at on the site don't quite seem to be what I am after? See example below.

http://jsfiddle.net/aaronk85/6PfKb/

Upvotes: 0

Views: 73

Answers (1)

Blair McMillan
Blair McMillan

Reputation: 5349

The jQuery hover method actually takes 2 functions, the first is for 'over' (or in) and the second if for 'off' (or out).

I've updated your fiddle with the correct syntax.

http://jsfiddle.net/6PfKb/9/

var $link = $('ul.internal-dropdown li.top-level');
$link.hover(function() {
    $(this).addClass('on');
}, function() {
    $link.removeClass('on');
});​

Upvotes: 7

Related Questions