how to append a row to a table with jquery in second position?

2.2k views Asked by At

I'm trying to add a row to a table with jquery. I would like to add the row in first position, but not the very first, I want it to come after the row dedicated to the column headers 'th'. If I try

$('#tableid').prepend() 

obviously the new row comes before the one of 'th's. Any idea of how to do that?

1

There are 1 answers

2
PSL On BEST ANSWER

Assuming your first tr that holds the th you could do:

$('#tableid tr:first').after(newTrContent);

Or you if have them separated out into thead and tbody then you could just do.

$('#tableid tbody').prepend(newTrContent);

Demo