I have a div with a nested link. The div has a delegate
handler for 'click'
, which alerts "Div". The link within the div also has a delegate
handler for 'click'
wherein e.preventDefault();
is called before alerting "Link". When I click the link, I see the "Div" alert, and the "Div" alert. I'm unclear why this is happening since I'm attempting to stop propagation from the link's click handler.
JavaScript
$('body').delegate('.outer', 'click', function(e){
e.preventDefault();
alert('Div');
});
$('body').delegate('.outer a', 'click', function(e){
e.preventDefault();
alert('Link');
// Note: I've also tried returning false (vs using preventDefault), per the docs
});
HTML
<div class="outer">
<a href="#">Click me</a>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…