I have a table filled with a number of rows. How can I remove all the rows from the table?
+6
A:
Use .remove()
$("#yourtableid tr").remove();
If you want to keep the data for future use even after removing it then you can use .detach()
$("#yourtableid tr").detach();
If the rows are children of the table then you can use child selector instead of descendant selector, like
$("#yourtableid > tr").remove();
rahul
2010-04-12 06:15:46
careful with that last one: most browsers add an implicit `tbody` element around the `tr` elements.
nickf
2010-04-12 06:20:57
+3
A:
Slightly quicker than removing each one individually:
$('#myTable').empty()
Technically, this will remove thead, tfoot and tbody elements too.
nickf
2010-04-12 06:19:19