how can i check, if clicked element is not child of some specific DIV element?
$("body").click(function(e) { if(e NOT child of $('#someDiv')) alert(1); }); if ($(e.target).parent('#someDiv').length == 0) { ... } Or, did you mean ("not an ancestor of e"):
if ($(e.target).closest('#someDiv').length == 0) { .closest() starts with the element itself and stops if it finds something. if by any chance the selector matches the child (like say using a class), it will return itself. .parents() would be safer..parent().closest('#someDiv')..on or .delegate.You can use the parent method with a selector to return the parent element if it matches that selector. You can then check the length property to see if the parent element was returned:
$("body").click(function(e) { if(!$(this).parent("#someDiv").length) { alert("Not a child"); } }); If you want to check whether the clicked element is not an ancestor, you can use parents instead of parent.