<table id="table">
<tr><td>one</td><td>two</td></tr>
<tr id="sum"><td>sum</td><td>sum2</td></tr>
</table>
<span id="add">add new</span>
$('#add').click(function(){
$('#table').append('<tr><td>one</td><td>two</td></tr>');
})
How can i make that this add new element with append as penultimate element?
I would like that #sum still are last element.
Use
insertBefore():JS Fiddle demo.
You could also simply use multiple
tbodyelements, one to contain the#sumrow, and the others for the, in this example,#content:With the jQuery:
JS Fiddle demo.
Or, possibly, using a
tfoot(though I’m not sure that this a proper use-case for atfootelement:And jQuery:
JS Fiddle demo.
References:
insertBefore().THEAD,TFOOT, andTBODYelements.