How can I delete all rows of an HTML table except the
Points to note, on the Watch out for common mistakes: If your start index is 0 (or some index from begin), then, the correct code is: NOTES 1. the argument for deleteRow is fixed 2. the rowCount is taken before the for loop starts
since as we delete the "table.rows.length" will keep on changing, so again you have some issue, that only odd or even rows only gets deleted. Hope that helps.\'s using Javascript, and without looping through all the rows in the table? I have a very huge
var tableHeaderRowCount = 1;
var table = document.getElementById('WRITE_YOUR_HTML_TABLE_NAME_HERE');
var rowCount = table.rows.length;
for (var i = tableHeaderRowCount; i < rowCount; i++) {
table.deleteRow(tableHeaderRowCount);
}
this is required since as we delete a row, the number of rows decrease.
i.e; by the time i reaches (rows.length - 1), or even before that row is already deleted, so you will have some error/exception (or a silent one).