# How to detect a click outside an element?

There are some HTML menus, which I would like to hide these elements when the user clicks outside the menus" area.

What could be the way to do so using jquery

$("#menuscontainer").clickOutsideThisElement(function() { // hide the menus }); A click event to the document body which closes the window. Attach a separate click event to the window which stops propagation to the document body.$('html').click(function() {