Please see the script; this will help you,
var $topLevelItems = $("nav > ul > li");
$('#nav').hover(function(){
if($('.level_2:visible').length>0){
$('.mod_navigation').animate({height:320},200);
}
},function(){
$('.mod_navigation').animate({height:50},200);
});
$topLevelItems.click(function() {
if (!$(this).hasClass('selected')) {
$topLevelItems.removeClass('selected')
.find('.level_2')
.slideUp();
$('.mod_navigation').animate({height:320},200);
$(this).addClass('selected')
.find('.level_2')
.slideDown();
}
});
Here is the demo
Please try this one too, This will handle the click function
var $topLevelItems = $("nav > ul > li");
$topLevelItems.click(function() {
if (!$(this).hasClass('selected')) {
$topLevelItems.removeClass('selected')
.find('.level_2')
.slideUp('slow');
$(this).addClass('selected')
.find('.level_2')
.slideDown('slow',function(){
$('.mod_navigation').animate({height:$topLevelItems.find('.level_2:visible').height()+55},200);
});
}
});