Given the html / css / javascript/jquery as follows, the event still fires when I click on ‘#bbb’.
Is there anyway to avoid this from happening?
<div id="aaa" style="position:absolute; width:100%; height:100%; background-color:#f00;">
<div id="bbb" style="height:25%; width:25%; background-color:#0f0; margin:0 auto;">
</div>
</div>
<script type="text/javascript">
$('#aaa').click(function(){alert('aaa clicked');});
</script>
Here you go:
e.targetpoints to the DOM element at which the click event was fired.thispoints to the#aaaelement (because it’s his click handler). Therefore, this linewill terminate the click handler early if the
#aaaelement wasn’t clicked directly.Live demo: http://jsfiddle.net/qbDZy/