Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery combining focus and hover

I am trying to use focus event on list element. it's working with hover, but not with focus! Do you have a idea ?

$('#main-menu ul.rubriques li')
.hover(function() {
$(this).addClass('active').find('ul').show();                    
})
.focus(function() {
$(this).addClass('active').find('ul').show();                    
});

i try to modify my code: and find the solution ;) ;) ;)

  $('#main-menu ul.rubriques li a')
.hover(function() { $(this).parent().addClass('active').find('ul').show();                   
})
.focus(function() { $(this).parent().addClass('active').find('ul').show();                   
});

thanks ! everybody !

like image 395
halna frédéric Avatar asked Feb 10 '26 15:02

halna frédéric


2 Answers

Focus is for <input/> elements and <a/> links...

like image 76
michelgotta Avatar answered Feb 15 '26 16:02

michelgotta


You can also bind both events at once:

$('#main-menu ul.rubriques li').bind('hover focus', function() {
    $(this).addClass('active').find('ul').show();                    
});

But like michelgotta says the focus is unlikely to work on an li except in some circumstances - http://api.jquery.com/focus/

like image 45
Richard Dalton Avatar answered Feb 15 '26 16:02

Richard Dalton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!