Skip to main content

A photo of Max Glenister

UX Design, UI Design & Front-end Development. Technically a cyborg.

Max Glenister

It's 2022 and :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>


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