How can I delete all rows of an HTML table except the const table = document.querySelector('table');
table.innerHTML === ' ' ? null : table.innerHTML = ' ';
the above javascript worked fine for me. It checks to see if the table contains any data and then clears everything including the header. If you do not want to remove Just Clear the table body. Assuming you have just one table so you can reference it with just the type.
If you don't want to delete the headers: otherwise: hope it helps! this will remove all the rows: this would work iteration deletetion in HTML table in native\'s using Javascript, and without looping through all the rows in the table? I have a very huge
th
and just want to remove the rows inside, this is working perfectly.var tb = document.getElementById('tableId');
while(tb.rows.length > 1) {
tb.deleteRow(1);
}
$("#tblbody").html("");
$("tbody").children().remove()
$("table").children().remove()
$("#table_of_items tr").remove();
document.querySelectorAll("table tbody tr").forEach(function(e){e.remove()})