公告
财富商城
积分规则
提问
发文
2020-05-11 21:05发布
手持菜刀,她持情操
I have an HTML table filled with a number of rows.
How can I remove all the rows from the table?
If you want to clear the data but keep the headers:
$('#myTableId tbody').empty();
The table must be formatted in this manner:
<table id="myTableId"> <thead> <tr> <th>header1</th><th>header2</th> </tr> </thead> <tbody> <tr> <td>data1</td><td>data2</td> </tr> </tbody> </table>
This will remove all of the rows belonging to the body, thus keeping the headers and body intact:
$("#tableLoanInfos tbody tr").remove();
$("#employeeTable td").parent().remove();
This will remove all tr having td as child. i.e all rows except the header will be deleted.
tr
td
$('#myTable > tr').remove();
最多设置5个标签!
If you want to clear the data but keep the headers:
The table must be formatted in this manner:
This will remove all of the rows belonging to the body, thus keeping the headers and body intact:
This will remove all
tr
havingtd
as child. i.e all rows except the header will be deleted.