Table deleteRow() Method
Definition and Usage
deleteRow()
Method to delete the row at the specified index from the table.
Tip:Use insertRow() Create and insert a new row.
See also:
HTML Reference Manual:HTML <tr> Tag
Example
Example 1
Delete the first row in the table:
document.getElementById("myTable").deleteRow(0);
Example 2
Delete the line you click on:
function deleteRow(r) { var i = r.parentNode.parentNode.rowIndex; document.getElementById("myTable").deleteRow(i); }
Example 3
Create and delete rows:
function myCreateFunction() { var table = document.getElementById("myTable"); var row = table.insertRow(0); var cell1 = row.insertCell(0); var cell2 = row.insertCell(1); cell1.innerHTML = "NEW CELL1"; cell2.innerHTML = "NEW CELL2"; } function myDeleteFunction() { document.getElementById("myTable").deleteRow(0); }
Syntax
tableObject.deleteRow(index)
Parameter value
Parameter | Description |
---|---|
index |
Required in Firefox and Opera, optional in IE, Chrome, and Safari. Integer, specifying the position of the line to be deleted (starting from 0). Value 0 will result in the first row being deleted. You can also use the value -1, which will result in the last row being deleted. If this parameter is omitted, deleteRow() will delete the last row in IE, and the first row in Chrome and Safari. |
Return Value:
No Return Value.
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |