insertCell method (tr)
Creates an empty cell element and inserts it into the current row element at the specified position.
This method provides a simpler way to create and insert a cell into a row than creating the cell with the createElement method and inserting it with the insertBefore method.
To remove a cell, use the deleteCell method.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
Returns the inserted cell element.
Example HTML code 1:
This example illustrates the use of the insertCell method:
|
||||
<head> <script type="text/javascript"> function InsertNewCell () { var table = document.getElementById ("table"); var firstRow = table.rows[0]; var cell = firstRow.insertCell (1); cell.innerHTML = "The new cell"; } </script> </head> <body> <button onclick="InsertNewCell ();">Insert a new cell!</button> <br /><br /> <table id="table" border="1px"> <tbody> <tr> <td>First cell in the row.</td> <td>Second cell in the row.</td> </tr> </tbody> </table> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
Related pages:
External links:
User Contributed Comments