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

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

c++ - In an add-in in Excel, written in C(++), how does one get the name of the function which called into the addin? -