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
Post a Comment