I am searching for a method to identify the initial parent element that includes another element with a specified class within it.
For instance:
<div class="wrapper">
<div class="item">
<div class="inner-element type-a">
</div>
</div>
<div class="item">
<!-- wish to target this one -->
<div class="inner-element type-b">
</div>
</div>
<div class="item">
<div class="inner-element type-b">
<!-- but not this one -->
</div>
</div>
</div>
Therefore, I want to employ
.wrapper .item:has(.inner-element.type-b)
to choose all of the item
divs that have an element with the type-b
class, however, my objective is to single out only the first one.
I attempted using
.wrapper .item:has(.inner-element.type-b):first-of-type
but it did not appear to pinpoint the element accurately. Is achieving this solely with CSS possible, or are my selector combinations problematic?