Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop event propagation when using delegate?

Tags:

jquery

When I use .bind to bind event on child and parent, child event can stop event propogation with return false; But when I use delegate, return false; does not stop event propagation.

http://jsfiddle.net/J3EAQ/

html:

<div class="parent">
    <div class="child"></div>
    <div class="child"></div>
</div>

js:

$('.parent').delegate('.child','click',function(e){
    alert('child click');
    return false;
});
$('.parent').bind('click',function(e){
    alert('parent click');
});
like image 960
codez Avatar asked Sep 16 '11 18:09

codez


1 Answers

e.stopPropagation() won't work in this case. Use e.stopImmediatePropagation() instead. Here's a fiddle

like image 61
aziz punjani Avatar answered Sep 24 '22 14:09

aziz punjani