$(document).click(function(evt) {
var target = evt.currentTarget;
var inside = $(\".menuWraper\");
if (target != inside) {
alert(\"bleep\");
The most common application here is closing on clicking the document but not when it came from within that element, for this you want to stop the bubbling, like this:
$(".menuWrapper").click(function(e) {
e.stopPropagation(); //stops click event from reaching document
});
$(document).click(function() {
$(".menuWrapper").hide(); //click came from somewhere else
});
All were doing here is preventing the click from bubbling up (via event.stopPrpagation()) when it came from within a .menuWrapper
element. If this didn't happen, the click came from somewhere else, and will by default make it's way up to document
, if it gets there, we hide those .menuWrapper
elements.