How do I detect a click outside an element?
Asked 07 September, 2021
Viewed 1.6K times
  • 59
Votes

I have some HTML menus, which I show completely when a user clicks on the head of these menus. I would like to hide these elements when the user clicks outside the menus' area.

Is something like this possible with jQuery?

$("#menuscontainer").clickOutsideThisElement(function() {
    // Hide the menus
});

30 Answer