Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using two functions with table

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?

like image 236
Fuxi Avatar asked Feb 03 '26 14:02

Fuxi


1 Answers

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().

like image 119
Nick Craver Avatar answered Feb 05 '26 03:02

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!