falcon
falcon

Reputation: 357

Removing two closest table rows with jQuery

$('table#Items').on('click','tr input#delItem',function(e){
    $(this).closest('tr').remove();
});

Hi all. Please tell me, what is the right solution for removing two table rows in lieu of one? Thank you

Upvotes: 0

Views: 1308

Answers (2)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

The following code will remove the next and the previous row from the closest row.

Try,

$('table#Items').on('click','tr input#delItem',function(e){
    var closestRow = $(this).closest('tr');
    closestRow.add(closestRow.prev()).add(closestRow.next()).remove();
});

Upvotes: 6

Mihai Matei
Mihai Matei

Reputation: 24276

Here is an example: http://jqversion.com/#!/72F15CA/1

$('table#Items').on('click','tr input#delItem', function(e){

    $(this).closest('tr').nextAll().slice(0,2).remove();
});

Upvotes: 3

Related Questions