Skip to content

Instantly share code, notes, and snippets.

@qustosh
Forked from ElmahdiMahmoud/gist:8451662
Created January 16, 2014 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qustosh/8451755 to your computer and use it in GitHub Desktop.
Save qustosh/8451755 to your computer and use it in GitHub Desktop.
js: hide a DIV when the user clicks outside of it
$(document).mouseup(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment