Delete the first cell(s) from a table row with id="myRow":
The deleteCell() method deletes a cell in the current table row.
Tip: Use the insertCell() method to delete a cell in the current table row.
The deleteCell() method is supported in all major browsers.
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. An integer (starts at 0) that specifies the position of the cell to delete in the current row.
The value of 0 results in that the first cell will be deleted.
The value of -1 can also be used; which result in that the last cell will be deleted. If this parameter is omitted, deleteCell() removes the last cell in IE and the first cell in Chrome and Safari. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. |
Return Value: | No return value. |
---|
Delete the last cell(s) from the a table row with id="myRow":
Delete cell(s) from the index position 1 in a table row with id="myRow":
Delete cell(s) at the beginning of the first table row. The table rows collection (.rows[0]) returns a collection of all <tr> elements in the table with id "myTable". The number [0] specifies the element to retrieve, in this example, the first table row. Then we use deleteCell() to delete cells from index position 0:
Insert new cell(s) with content at the beginning of a table row with id="myRow":