I have set of 6 elements and I would like to filter by every second and third element so I want to have elements 2, 3, 5 and 6. I've tried .filter(':nth-child(2n+1)'));
but obviously that filters the 2, 4, and 6.
The other way I was trying was to remove elements 1 and 4, but I couldn't find a jQuery function that was the opposite of filter that would remove the elements from the set.
.filter(':not(:nth-child(1),:nth-child(4))')
http://jsbin.com/owosuw/2/edit#source
Going by your example, I don't think you actually want 2n and 3n. You want the 2nd and 3rd out of every group of 3? Then either one of these should work:
.filter(':nth-child(3n+2), :nth-child(3n+3)'));
.filter(':not(:nth-child(3n+1))');
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