开发者

Select elements with display:list-item

开发者 https://www.devze.com 2023-02-11 05:04 出处:网络
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 on

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号