JavaScript Drop down navigation on click

Traditional drop-down navigation is activated on hover. With some additional even handling, you can make it activate on click.
$('ul#nav').children('li').children('a').click(function(e) {
	if ($(this).siblings('ul').length === 0)
		return;

	e.preventDefault();
	$(this).parent().siblings().find('ul').hide();
	$(this).siblings('ul').stop(0,1).slideToggle('fast'); 
});

$('ul#nav').children('li').mouseleave(function() {
	$(this).find('ul').stop(0,1).slideUp('fast');	
});
Posted by
Snippet Viewed 1211 times.

Share your JavaScript code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent javascript snippets

Most Viewed