Search w3schools.com:

SHARE THIS PAGE

Table deleteRow() Method

Table Object Reference Table Object

Definition and Usage

The deleteRow() method removes the row at the specified index from a table.

Syntax

tableObject.deleteRow(index)

Value Description
index An integer that specifies the position of the row to delete (starts at 0). The value of -1 can also be used; which result in that the last row will be deleted.

This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari.

If this parameter is omitted, deleteRow() removes the last row in IE and the first row in Chrome and Safari.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

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


Example

Example

Delete the first row in the table:

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

</body>
</html>

Try it yourself »


Examples

More Examples

Delete the row you click on
This example uses deleteRow() to delete the row you click on.


Table Object Reference Table Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]