In this tutorial, you will learn how to delete/remove all the table rows except the first one in jquery.
This is usually required when we need to load new data from the ajax but we don’t want to remove the first row.
We will cover the multiple ways of doing that in jquery. Let’s get started
Here is the first solution on how to remove all rows except the first one:
In the above code, the
tableselector is the selector of the table, and
tr:gt(0) means removing all the rows which are greater than 0 and 0 is considered as the first row.
Another way of doing this using the
Third way of doing this using the
$(".tableselector").children( 'tr:not(:first)' ).remove();
Hope you have learned today on how to remove or delete all the table rows except the first one in jquery.
Let me know if you have any questions in the comments.
Keep learning, see you in the next one.