Event on a click everywhere on the page outside of the specific div

Attach a click event to the document to hide the div:

$(document).click(function(e) {
   $('#somediv').hide();
});

Attach a click event to the div to stop clicks on it from propagating to the document:

$('#somediv').click(function(e) {
   e.stopPropagation();
});

Leave a Comment