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
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.