I have an HTML table with a header and a footer:
<table id="myTable">
<thead>
<tr>
<th>My Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>aaaaa</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>My footer</td>
</tr>
<tfoot>
</table>
I am trying to add a row in tbody
with the following:
myTable.insertRow(myTable.rows.length - 1);
but the row is added in the tfoot
section.
How to insert it tbody
?
You're close, just add the row to the
tbody
instead oftable
:Just get a reference to
tBody
(myTbody
) before use. Notice, that you don't need to pass the last position in a table, it's automatically positioned at the end when omitting argument.A live demo at jsFiddle.
You can use following example
JS file:
add rows
and cells
I think this is the best way to add a row to the table:
I think this script is what exactly you need
You can try following snippet using Jquery.