views:

201

answers:

3

I have var row=<tr><td>val</td><td>val2</td></tr>. and i tried this:

$("#mainTable tbody").append(row);

but he appends to the end of the table.

I also tried $("#mainTable tr:first").after().append(row);

but have not got a result yet.

Please, help me to understand

+2  A: 

InsertAfter is what you are looking for:

var row='<tr><td>val</td><td>val2</td></tr>';
$(row).insertAfter("#mainTable tr:first");
Dexter
A: 

This should help, as it has already been asked: http://stackoverflow.com/questions/171027/jquery-add-table-row

Dustin Laine
+2  A: 

Try this:

$("#mainTable tr:first").after(row);

http://api.jquery.com/after/

TiuTalk