Help needed: how to keep drop down menu showing on hover and close only on click
Hi everyone,
I looked everywhere, couldn't find the solution.
I have a navigation menu with dropdowns,
I need the dropdown to be open on hover/mouseenter always, even the user change tabs or navigate inside dropdown menu.
And close only on 'X' close button.
The sample code:
$('.main-nav ul > li').mouseenter(function(e){
- $(this).addClass('active').find('.dropdown-menu').show();
- }).mouseleave(function(e){
- $(this).removeClass('active').find('.dropdown-menu').hide();
-
- });
-
- $('.dropdown-menu .close').click( function(e){
- e.stopPropagation();
- $('.dropdown-menu').hide();
- $('.dropdown .dropdown-toggle').parent().removeClass('active');
- console.log('close btn!');
- });
How to keep dropdown open on mouseleave?
Is it any better way to do it?
The functionality should be aka Bootstrap: show dropdown on hover, keep it open when navigating through the menu items and submenus, keep dropdown showing even when open Dev tools or mouse over other elements on web page, close it only on button '.close' click or re-load the page.
Any ideas highly appreciated.