Search w3schools.com:

SHARE THIS PAGE

tr deleteCell() Method

tr Object Reference tr Object

Definition and Usage

The deleteCell() method deletes a cell in the current table row.

Syntax

trObject.deleteCell(index)

Value Description
index An integer (starts at 0) that specifies the position of the cell to delete in the current row. 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.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The deleteCell() method is supported in all major browsers.


Example

Example

Delete first cell from the first table row:

<html>
<head>
<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 first cell</button>

</body>
</html>

Try it yourself »


tr Object Reference tr Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]