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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -