TableRow deleteCell() Method
Definition and Usage
deleteCell()
The method deletes a cell from the current table row.
Tip:Use insertCell() Method Insert a cell in the current table row.
See also:
HTML Reference Manual:HTML <tr> Tag
Instance
Example 1
Delete the first cell from the table row with id="myRow":
var row = document.getElementById("myRow"); row.deleteCell(0);
Example 2
Delete the last cell from the table row with id="myRow":
var row = document.getElementById("myRow"); row.deleteCell(-1);
Example 3
Delete the cell from the index position 1 of the table row with id="myRow":
var row = document.getElementById("myRow"); row.deleteCell(1);
Example 4
Delete the cell at the beginning of the first table row.
The rows collection (.rows[0]) of the table returns a collection of all <tr> elements in the table with id "myTable". The number [0] specifies the element to be retrieved, which in this case is the first table row.
Then we use deleteCell() to delete the cell from the index position 0:
var firstRow = document.getElementById("myTable").rows[0]; firstRow.deleteCell(0);
Example 5
Insert a new cell containing content at the beginning of the table row with id="myRow":
var row = document.getElementById("myRow"); var x = row.insertCell(0); x.innerHTML = "new cell";
Syntax
tablerowObject.deleteCell(index)
Parameter | Description |
---|---|
index |
It is required in Firefox and Opera, and optional in IE, Chrome, and Safari. An integer (starting from 0) that specifies the position of the cell to be deleted in the current row. Value 0 causes the first cell to be deleted. The -1 value can also be used, which results in the last cell being deleted. If this parameter is omitted, deleteCell() will delete the last cell in IE and the first cell in Chrome and Safari. |
Technical Details
Return Value:
No Return Value.
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |