Created
January 21, 2019 22:49
-
-
Save jp26jp/551fff1725463b2743f33d2cb55603d7 to your computer and use it in GitHub Desktop.
Hides a div when a click occurs outside of the specified container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).click(function(e) { | |
let 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