Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery add row before fourth to last row

I have an invoice table. The last four rows are as follows, starting from last: Grand Total, Tax, Subtotal, Add a line link.

So I need to add a row before the "Add a link link row".

This thread Add table row in jQuery shows how to add a row after the last row. I just need to modify it, to add a row before the fourth to last row.

like image 532
leonel Avatar asked Dec 15 '11 17:12

leonel


1 Answers

how about you add a class to your grand total row

<tr class="grand-total"></tr>

then in jquery you do

$('#myTable tr.grand-total').before('<tr></tr>');

this way you are not doing it based on a position that might be changing, but instead based on something meaningful like 'grand total'

like image 116
Bassam Mehanni Avatar answered Oct 03 '22 22:10

Bassam Mehanni