Alex Aung
Alex Aung

Reputation: 3159

jQuery exclude first, second and last table row

I am excluding first and last table row to calculate summary. Now added one more header with merging. So I need to skip second row as well. So I need to skip

first, second and last. I have added tr:not(:first,second, last) but It is not working. May I know how can I skip second row of table in this script.

Thanks,

$(".printer-type tr:not(:first, last) td:last-child").text(function() {
  var totalVal = 0;
  $(this).prevAll().each(function() {
    totalVal += parseFloat($(this).children('.txtfld').val()) || 0;
    //totalVal += parseInt( );
  });
  return parseFloat(totalVal).toFixed(1);
});

Upvotes: 0

Views: 2452

Answers (3)

Satpal
Satpal

Reputation: 133453

You can use :lt(index)

Select all elements at an index less than index within the matched set.

$(".printer-type tr:not(:lt(2), :last) td:last-child")

:gt(index) can also be used

Select all elements at an index greater than index within the matched set.

$(".printer-type tr:gt(1):not(:last) td:last-child")

Upvotes: 2

charlietfl
charlietfl

Reputation: 171698

Can use slice() instead of selectors

$('.printer-type tr').slice(1,-1).children(':last-child')

DEMO

Upvotes: 1

Álvaro Touzón
Álvaro Touzón

Reputation: 1230

:last for last item , and :eq(index) for second

Upvotes: 0

Related Questions