I am having a table and I want to remove all <tr>
of the table except the first one. How can I do this.?
There are several methods here, the most terse is to use the :gt()
selector, like this:
$('#tableID tr:gt(0)').remove();
Is there a special meaning to the first row? I am going to go out on a limb and say the first row is likely the row which contains the column headings.
If so, one easy option is to put the first row in a <thead>
and all the body rows in a <tbody>
. Then you could simply do:
$('#myTable tbody tr').remove();
This also gives your HTML more semantic meaning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With