javascript - How do I detect a click outside an element? -


i have html menus, show when user clicks on head of these menus. hide these elements when user clicks outside menus' area.

is possible jquery?

$("#menuscontainer").clickoutsidethiselement(function() {     // hide menus }); 

note: using stopeventpropagation() should avoided breaks normal event flow in dom. see this article more information. consider using this method instead.

attach click event document body closes window. attach separate click event window stops propagation document body.

$(window).click(function() { //hide menus if visible });  $('#menucontainer').click(function(event){     event.stoppropagation(); }); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -