本文介绍了元素的jquery选择器MISSING子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助形成一个jquery选择器来返回缺少特定子元素的元素。
I am needing help forming a jquery selector to return elements which are missing a particular child element.
给出以下HTML片段:
Given the following HTML fragment:
<div id="rack1" class="rack">
<span id="rackunit1" class="rackspace">
<span id="component1">BoxA</span>
<span id="label1">Space A</span>
</span>
<span id="rackunit2" class="rackspace">
<span id="label2">Space B</span>
</span>
<span id="rackunit3" class="rackspace">
<span id="component2">BoxA</span>
<span id="label3">Space C</span>
</span>
</div>
<div id="rack2" class="rack">
<span id="rackunit4" class="rackspace">
<span id="component3">BoxC</span>
<span id="label4">Space D</span>
</span>
<span id="rackunit5" class="rackspace">
<span id="label5">Space E</span>
</span>
<span id="rackunit6" class="rackspace">
<span id="component4">BoxD</span>
<span id="label6">Space F</span>
</span>
</div>
为我找到没有组件跨度的rackunit跨度。
到目前为止,我有:
$(。rack .rackspace)来获取所有机架单元跨度,不确定如何排除具有组件跨度的那些或仅选择那些没有一个。 。
Find for me the rackunit spans with NO component span.Thus far I have:$(".rack .rackspace") to get me all of the rackunit spans, not sure how to either exclude those with a component span or select only those without one...
推荐答案
我想以下情况应该有效:
I guess the following should work:
$(".rack .rackspace:not(:has(span[id^=component]))"). ...
DEMO:
这篇关于元素的jquery选择器MISSING子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!