Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select 2nd and 3rd element from each triplet of elements

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.

like image 824
Paul Sham Avatar asked Dec 27 '22 02:12

Paul Sham


2 Answers

.filter(':not(:nth-child(1),:nth-child(4))')

http://jsbin.com/owosuw/2/edit#source

like image 140
Vlad Minaev Avatar answered Jan 08 '23 23:01

Vlad Minaev


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))');
like image 41
ephemient Avatar answered Jan 08 '23 23:01

ephemient