I'm trying to select every third visible child of an ul. I tried to use :visible but don't get it to work. Is there another way of selecting elements with display:list-item? I figured :visible is only looking at display:block开发者_如何学C?
If you're using nth-child
, it doesn't take into account the subset returned by :visible
when determining its nth
position.
You'll first need to select the visible ones, then do a .filter()
.
Example: http://jsfiddle.net/YNV3J/
$('ul > li:visible').filter(function(i) {
return i % 3 === 2;
}).addClass('third');
EDIT: Original answer was using nth-child
which will fail in this situation. Fixed.
精彩评论