Skip to content

Instantly share code, notes, and snippets.

@sagarjadhav
Last active December 22, 2015 19:49
Show Gist options
  • Save sagarjadhav/6522072 to your computer and use it in GitHub Desktop.
Save sagarjadhav/6522072 to your computer and use it in GitHub Desktop.
jQuery to hide a DIV when the user clicks outside of it.
$(document).mouseup(function (e) {
var container = $("YOUR CONTAINER SELECTOR");
/* if the target of the click isn't the container */
/* Nor a descendant of the container */
if ( !container.is(e.target) && container.has(e.target).length === 0) {
container.hide();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment