It's 2022 and #CSS :only-child isn't aware of text nodes?

I'm trying to select an image that is the only direct descender of an element, with no text node siblings, e.g.:

<div><img/></div>

Not

<div>Hello<img/>World</div>

div img:only-child will select this img in both cases, as will div img:first-child and div img:last-child

Am I missing something?

Follow

@omgmog Because that'd quickly became a pain as HTML often has whitespace (which are also text nodes) between elements:

<div class="a">
<div class="b">...</div>
</div>

Nobody wants to deal with that.

Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!