Alex Rivera | Logout

How to remove all rows from a table except first two and last?

Asked 2012-07-05T18:17:35.847
11

I've seen a lot of questions about how to select all but the first and last rows of a table, but I want to know how to select everything except the first TWO rows and the last. Right now I have this to select all but the first two:

$("#sometable").find("tr:gt(1)").remove();

and I need some way to get the last one as well. Maybe some way to combine with

:not(:last)

?

I'm fairly new to jQuery and any help would be appreciated.

Edit
Report

1 Answer

12

Just combine the selectors:

$("#sometable").find("tr:gt(1):not(:last)").remove();

JSFiddle

answered 2012-07-05T18:19:58.217

Your Answer