I am needing help forming a jquery selector to return elements which are missing a particular child element.
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>
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: http://jsfiddle.net/WbCzj/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With