open and close submenus on click Jquery

前端 未结 2 1082
天涯浪人
天涯浪人 2021-01-18 11:21

I have a main menu that will display the submenus with a click event in jquery (client wanted to be click instead hover) so I got it working however I still can\'t figure ou

2条回答
  •  感动是毒
    2021-01-18 11:34

    Just Add this line into your code

    $('#MainMenu > li').not(this).find('ul').slideUp();
    

    FULL CODE

    $('#MainMenu').find('> li').click(function() {
        $('#MainMenu > li').not(this).find('ul').slideUp();
        $(this).find('ul').stop(true, true).slideToggle(400);
        return false;
    });​
    

    Check Fiddle

提交回复
热议问题