Table deleteRow() Method - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Table

Description

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

Syntax

table.deleteRow(index);

Parameter Values

Value Description
index Required in Firefox and Opera, optional in IE, Chrome and Safari.

-1 removes the last row will be deleted.

Return Value:

No return value

The following code shows how to Delete the first row in a table:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, td {
    border: 1px solid black;
}
</style>/*w  w w .  j ava  2  s  .  c o m*/
</head>
<body>

<table id="myTable">
  <tr>
    <td>Row1 cell1</td>
    <td>Row1 cell2</td>
  </tr>
  <tr>
    <td>Row2 cell1</td>
    <td>Row2 cell2</td>
  </tr>
  <tr>
    <td>Row3 cell1</td>
    <td>Row3 cell2</td>
  </tr>
</table>
<br>

<button onclick="myDeleteFunction()">Delete row</button>

<script>

function myDeleteFunction() {
    document.getElementById("myTable").deleteRow(0);
}
</script>

</body>
</html>

Related Tutorials