Jquery: Show/hide menu with single button

后端 未结 1 492
情歌与酒
情歌与酒 2021-01-27 13:02

I am trying to make a button that calls a menu. After the menu has been called, clicking on the button should close the menu.

There are also some classes that should be

1条回答
  •  时光说笑
    2021-01-27 13:59

    When you click on an element, the click event is triggered and it bubbles up to all containing elements. Both the body and the document will receive this event.

    To fix your code, you need to listen from the same place.

    Just change $(document) to $('body').

    JSFiddle: http://jsfiddle.net/d4ajx/1/

    See this diagram for more information.

    0 讨论(0)
提交回复
热议问题