How do I select an element that has no visible siblings using jQuery?
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/
精彩评论