开发者

How do I select an element that has no visible siblings using jQuery?

开发者 https://www.devze.com 2023-04-12 16:04 出处:网络
I know I could do this with some extra javascri开发者_StackOverflow中文版pt, but I\'m guessing there is a way to it using just a jQuery selector.

I know I could do this with some extra javascri开发者_StackOverflow中文版pt, but I'm guessing there is a way to it using just a jQuery selector.

The element(s) I'm looking for will have siblings that have just (on the previous JS line) had their display property set to none. if the element(s) have even one visible sibling, I don't want a match.

Thanks a ton.


There might be a more concise way, but this should work:

var siblings = $('#myItem').siblings(":visible").length;
var item = siblings == 0 ? $('#myItem') : null;
alert(item);

You can see the fiddle here: http://jsfiddle.net/JmwcR/23/

0

精彩评论

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