UK [inˈsə:t rəu] US [ɪnˈsɚt ro]
[理] insert row
javascript insertRow() method syntax
Function: Used to insert a new row at the specified position in the table.
Syntax: tableObject.insertRow(index)
Returns: Returns a TableRow, representing the newly inserted row.
Description: This method creates a new TableRow object, representing a new <tr> tag, and inserts it into the table at the specified position. The new row will be inserted before the row at index. If index is equal to the number of rows in the table, new rows will be appended to the end of the table. If the table is empty, the new row will be inserted into a new <tbody> section, which will itself be inserted into the table.
Note: You can use the TableRow.insertCell() method to add content to newly created rows.
javascript insertRow() method example
<html> <head> <script type="text/javascript"> function insRow() { document.getElementById('myTable').insertRow(0) } </script> </head> <body> <table id="myTable" border="1"> <tr> <td>Row1 cell1</td> <td>Row1 cell2</td> </tr> <tr> <td>Row2 cell1</td> <td>Row2 cell2</td> </tr> </table> <br /> <input type="button" onclick="insRow()" value="Insert new row"> </body> </html>
Run instance »
Click the "Run instance" button to view the online instance