Hi First at all Check this example Demo Fiddle
:
Here I use this functions all you need is change your selectors according to the HTML structure you want, I propose you one in the fiddle:
First the handlers to show and hide the submenu:
function showsub(){ $(this).parent().find( ".submenu").slideDown(50); } function hidesub(){ $(this).parent().find( ".submenu" ).slideUp(50); };
Attach the events to the
.hover()
$('.trigger').hover(showsub,hidesub);
And make the click function, here I use
unbind
after the first click and after the second bind again the functions.$('.trigger').click(function() { $(this).parent().find('.triggercontainer').slideToggle(250); var state = $(this).data('state'); if(state === "off"){ $(this).parent().find( ".submenu" ).show(); $(this).data('state','on'); $(this).unbind('mouseenter mouseleave'); } else { $(this).parent().find( ".submenu" ).slideUp(50); $(this).data('state','off'); $(this).on('mouseenter',showsub).on('mouseleave',hidesub); } });