I have a navigation with a nested ul
list structure like this
<ul id='mainNav'>
<li> Some Stuff!
<ul>
<li>Page 1</li>
<li>Page 2</li>
</ul>
</li>
<li> Hover here to login!
<ul >
<li>
<div class='login'>
<p>Login</p>
<input type='password'>
<button>Okay</button>
</div>
</li>
</ul>
</ul>
and I am using jQuery to display the menu on hover
$('ul#mainNav > li').hover(function() {
$(this).addClass("showMenu");
},
function(){
$(this).removeClass("showMenu");
}
);
While this works well, there is an issue with the input box for the login. When moving the mouse from the input box to a browser suggestion, jQuery interprets it as leaving the li
element and removes the showMenu class, causing the submenu to disappear.
When hovering over the li
element, the login form opens
https://i.sstatic.net/akwMR.png
However, when hovering over a browser suggestion, the li
element disappears except for the browser suggestion itself
https://i.sstatic.net/JH4Fs.png
I have also created a jFiddle.
Is there a way to make jQuery continue hovering even if moving from the input element to a browser suggestion?