Javascript DOM HTML TableRow deleteCell() Method

Introduction

Delete the first cell(s) from a table row with id=myRow:

Click the button to delete the first cell(s) from the table row.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, td {
  border: 1px solid black;
}
</style>//from w w w. j a v  a 2 s  .  co m
</head>
<body>
<table>
  <tr id="myRow">
    <td>First cell</td>
    <td>Second cell</td>
    <td>Third cell</td>
  </tr>
</table><br>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  var row = document.getElementById("myRow");
  row.deleteCell(0);
}
</script>

</body>
</html>

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

Parameter Values

Value Description
index Required. the position of the cell to delete in the current row, starting at 0.



PreviousNext

Related