tr deleteCell()Method
tr Object
Definition and Usage
The deleteCell() method is used to delete a cell (<td> element) from a table row.
Syntax
trObject.deleteCell(index)
| Value | Description |
|---|---|
| index | The parameter index is the position of the cell to be deleted in the row. This method will delete the cell at the specified position in the table row. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the deleteCell() method
Example
Example
The following example deletes a cell from a row:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete the first cell</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete the first cell</button>
</body>
</html>
Try it Yourself »
tr Object Other Extensions