Table deleteRow()Method
Table Object
Definition and Usage
The deleteRow() method is used to delete a row at a specified position in a table.
Syntax
tableObject.deleteRow(index)
| Value | Description |
|---|---|
| index | A number that specifies the index of the row to delete (starts at 0). |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the deleteRow() method.
Example
Example
Delete the first row of the table:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").deleteRow(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete First Table Row</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").deleteRow(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete First Table Row</button>
</body>
</html>
Try it Yourself »
More Examples
Delete a table row after clicking
This example uses the deleteRow() method to delete a row after clicking.
Table Object Other Extensions