问题
The thing I need (prob with Jquery) is to loop through all elements in my ul (dynamically driven content) if they all still have this special attrbitue pl_id (the value may vary)
If all elements within this ul still contain the attribute then the button still needs to be in place. If one element is added the button has to disappear... I'm confused how to approach this.
<ul id="tracks">
<li pl_id="14" class="item" id="5" ytid="SnA52s7qceM" artist="Michael Bublé" albname="Christmas" track="Santa Claus Is Coming to Town" cdnr="1" trnr="2" length2="02:51"></li>
<li class="item" id="1" ytid="8OsgqpnuizY" artist="Michael Bublé" albname="Christmas" track="White Christmas" cdnr="1" trnr="4" length2="03:37"></li>
</ul>
So in this case the second li does not have the pl_id attr. So my like button (or whatever function) needs to disappear. As soon as ALL the li's in this ul have this attr the button needs to be there! Thanks.
回答1:
Theoretically the following code might help you:
$("#buttonID").toggle($("ul > li").filter(function() {
return !this.hasAttribute("pl_id");
}).length === 0);
DEMO: http://jsfiddle.net/HBbk3/
来源:https://stackoverflow.com/questions/13691630/loop-through-all-elements-dynamically-driven-content-if-they-all-still-have-sp