Created
May 7, 2014 10:51
Detect if clicked/touched outside some block
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
// 'touchstart' helps trigger the event in touch devices | |
$(document).on('click touchstart', function(e){ | |
if ($(e.target).closest("#menuscontainer").length == 0) { | |
// .closest can help you determine if the element | |
// or one of its ancestors is #menuscontainer | |
console.log("hide"); | |
} | |
}); | |
$('#menuscontainer').on('click', function(e){ | |
e.stopPropagation(); | |
e.preventDefault(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment