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
?
Basic Approach:
This should add html formatted content and show newly added row.
I have tried this,
this is working for me
If you want to add a row into the
tbody
, get a reference to it and add it there.A working demo here. Also you can check the documentation of
insertRow
here.