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:only-child will select this img in both cases, as will div img:first-child and div img:last-child

Am I missing something?


@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>

Nobody wants to deal with that.

Sign in to participate in the conversation

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