How can I delete all rows of an HTML table except the this is a simple code I just wrote to solve this, without removing the header row (first one). Hope it works for you!!. How about this: When the page first loads, do this: Then when you want to clear the table: The result will be your header row(s) if that's all you started with, the performance is dramatically faster than looping. Assing some id to tbody tag. i.e. . After this, the following line should retain the table header/footer and remove all the rows. And, if you want the entire table (header/rows/footer) to wipe out, then set the id at table level i.e. This works in IE without even having to declare a var for the table and will delete all rows: Keep the i.e. the give below code works great.
It removes all rows except header row. So this code really t \'s using Javascript, and without looping through all the rows in the table? I have a very huge
var Tbl = document.getElementById('tblId');
while(Tbl.childNodes.length>2){Tbl.removeChild(Tbl.lastChild);}
var myTable = document.getElementById("myTable");
myTable.oldHTML=myTable.innerHTML;
myTable.innerHTML=myTable.oldHTML;
document.getElementById("yourID").innerHTML="";
for(var i = 0; i < resultsTable.rows.length;)
{
resultsTable.deleteRow(i);
}
<th>
row in a <thead>
and the other rows in a <tbody>
then replace the <tbody>
with a new, empty one.var new_tbody = document.createElement('tbody');
populate_with_new_rows(new_tbody);
old_tbody.parentNode.replaceChild(new_tbody, old_tbody)
$("#Your_Table tr>td").remove();