loop through all elements (dynamically driven content) if they all still have special attrbitue

帅比萌擦擦* 提交于 2019-12-11 08:42:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!