Skip to content

Instantly share code, notes, and snippets.

@guilhermemarconi
Created January 11, 2020 20:28
Show Gist options
  • Save guilhermemarconi/500677f4907e66866a3718d39cfad1a2 to your computer and use it in GitHub Desktop.
Save guilhermemarconi/500677f4907e66866a3718d39cfad1a2 to your computer and use it in GitHub Desktop.
Interact with element when clicking outside of it
const $wrapper = $('.my-element');
$(document).on('click', e => {
if (!$wrapper.is(e.target) && $wrapper.has(e.target).length === 0) {
// do your stuff
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment