If the e.target
is the same element as this
, you've not clicked on a descendant.
$('.foobar').on('click', function(e) {_x000D_
if (e.target !== this)_x000D_
return;_x000D_
_x000D_
alert( 'clicked the foobar' );_x000D_
});
_x000D_
.foobar {_x000D_
padding: 20px; background: yellow;_x000D_
}_x000D_
span {_x000D_
background: blue; color: white; padding: 8px;_x000D_
}
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>_x000D_
<div class='foobar'> .foobar (alert) _x000D_
<span>child (no alert)</span>_x000D_
</div>
_x000D_