You are here: Reference > JavaScript > client-side > HTML DOM > methods > insertRow (table, tbody, tfoot, thead)
insertRow method (table, tbody, tfoot, thead)
This method provides a simpler way to create and insert a row than creating the row with the createElement method and inserting it with the insertBefore method.
To remove a row, use the deleteRow method.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
Returns the inserted row element.
Example HTML code 1:
This example illustrates the use of the insertRow method:
|
||||
<head> <script type="text/javascript"> function InsertNewRow () { var table = document.getElementById ("table"); var row = table.insertRow (1); var cell = row.insertCell (0); cell.innerHTML = "New row"; } </script> </head> <body> <button onclick="InsertNewRow ();">Insert a new row!</button> <br /><br /> <table id="table" border="1px"> <tbody> <tr> <td>First row.</td> </tr> <tr> <td>Second row.</td> </tr> </tbody> </table> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments