I need to get only the first matched elements from my tree (if element was found no need to go deeper). The problem is that this element can be wrapped into nested divs, so I can’t use > selector.
My code is like this:
<div id="root">
<div class="sub">I need this element</div>
<div>
<div class="sub">I need this element</div>
</div>
<div class="sub">
<div class="sub">I don't need this element</div>
</div>
</div>
Can’t find solution 🙁
If you can’t use the child selector, try
This selects only those
.subelements which are not descendants of other.subelements.Alternatively:
which also works if
#rootis inside a.sub.Edit: Or see @RightSaidFred’s comment for this case.