How to remove all rows from a table except first two and last?
html-table, jquery, jquery-selectors
Solution
This is what you need:
$("#sometable").find('tr').slice(2,-1).remove()
DEMO
jsperf of my and @Evan's solutions.
Problem
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.