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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -