akram akram - 5 months ago 78
HTML Question

Delete all rows in an HTML table

How can I delete all rows of an HTML table except the

's using Javascript, and without looping through all the rows in the table? I have a very huge table and I don't want to freeze the UI while I'm looping through the rows to delete them


Keep the <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');
old_tbody.parentNode.replaceChild(new_tbody, old_tbody)