document.addEventListener("click", function (e) {
var level = 0;
for (var element = e.target; element; element = element.parentNode) {
if (element.id === 'x') {
document.getElementById("out").innerHTML = (level ? "inner " : "") + "x clicked";
return;
}
level++;
}
document.getElementById("out").innerHTML = "not x clicked";
});
stackoverflow.com/questions/14188654/detect-click-...document.addEventListener("click", function (e) {
for (var element = e.target; element; element = element.parentNode) {
if (element.id === 'block_id') {
return;
}
}
var obj = document.getElementById('block_id');
if (obj.style.display == "block")
obj.style.display = "none";
});