Insert a new row of a table after the first row of a table using jQuery

I have a table with id="#table" and then the first row with id="headings" , now right after the header line I need to insert a new row

I am using the following code

$("#headings").after($("#table").prepend("<tr>...</tr>"));

but i think i'm doing something wrong here

+4
source share
2 answers

Well, .after() ref and .prepend() ref require an "HTML string", "DOM node" or "jQuery" as an argument.

So it’s actually enough to call

 $('#headings').after('<tr><td></td></tr>'); 
+8
source

Maybe $("#table tr:first").after("<tr><td>some</td><td>content</tr></tr>"); could be easier? Here is a demo .

+11
source

All Articles