tags:

views:

57

answers:

2
+5  Q: 

clear table jquery

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
careful with that last one: most browsers add an implicit `tbody` element around the `tr` elements.
nickf
+3  A: 

Slightly quicker than removing each one individually:

$('#myTable').empty()

Technically, this will remove thead, tfoot and tbody elements too.

nickf