Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Last active August 29, 2015 13:57
Show Gist options
  • Save dustintheweb/9924104 to your computer and use it in GitHub Desktop.
Save dustintheweb/9924104 to your computer and use it in GitHub Desktop.
If you click outside of a specific div, do something
$('body').on('touchstart click', $staticSection, function(e) {
var $target = $(e.target);
if(!$target.closest($someSection).length) {
// do something... ex: $someSection.removeClass('open');
}
});
// conditional example
$('body').on('touchstart click', $staticSection, function(e) {
var $target = $(e.target);
if ($('body').is($someClass) && !$target.closest($someSection).length) {
// do something... ex: $someSection.removeClass('open');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment