<div id="home">
<div id="second"></div>
</div>
#home {
width: 100px;
height: 100px;
background-color: red;
}
#second {
width: 20px;
height: 20px;
background-color: green;
}
$(window).click(function(e) {
if(e.target.id == 'home'){
alert('This is div home!');
}
});
Now if i click on green div then this doesnt working, but this div is in div red.
Is possible automatically add all children div id home for this? If this div have 100 children then i have must add 100 if?
You’ll want to check if the target element is within the
#homediv:Here’s the fiddle: http://jsfiddle.net/6sY49/