views:

18

answers:

1

hi all,

i made a little listview widget which uses a table and assigned a function to its rows like:

$("tr",myTable).bind("click",function(){
    selectRow($(this));
});

i now would like to apply another function called deleteRow, but only to each row's last cell:

$("td:last-child",myTable).bind("click",function(){
    deleteRow($(this));
});

my question: when clicking the last cell for deleting a row, i don't want the selectRow function to be fired - how can i avoid this?

thx

+2  A: 

You can stop the click from bubbling up to the <tr>, like this:

$("td:last-child",myTable).bind("click",function(e){
    deleteRow($(this));
    e.stopPropagation();
});

Since your other click handler is on the <tr>, it won't fire, since you stopped it from bubbling up using event.stopPropagation().

Nick Craver
thanks that helped :) i also found out that adding "return false" also seems stopping the bubbling-up, but not sure if it works the same as stopPropagation.
Fuxi
@Fuxi - It does, it triggers `stopPropgation()` *and* `preventDefault()` under the covers :)
Nick Craver