Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The insertRow() method of the HTMLTableElement interface inserts a new row (<tr>) in a given <table>, and returns a reference to the new row.
If a table has multiple <tbody> elements, by default, the new row is inserted into the last <tbody>. To insert the row into a specific section, use HTMLTableSectionElement.insertRow()
Note: insertRow() inserts the row directly into the table. The row does not need to be appended separately as would be the case if Document.createElement() had been used to create the new <tr> element.
HTMLTableElement is a reference to an HTML <table> element.
The row index of the new row. If index is -1 or equal to the number of rows, the row is appended as the last row. If index is omitted it defaults to -1.
An HTMLTableRowElement that references the new row.
Thrown if index is greater than the number of rows.
This example uses insertRow(-1) to append a new row to a table.
We then use HTMLTableRowElement.insertCell() to insert a new cell in the new row. (To be valid HTML, a <tr> must have at least one <td> element.) Finally, we add some text to the cell using Document.createTextNode() and Node.appendChild().
| HTML # dom-table-insertrow-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Nov 3, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.