mardi 5 juillet 2016

Select inline elements without text siblings

I need to select inline HTML elements that are the only thing inside their parent element - that is, there is no text or other inline elements before or after them.

<p><img src="foo.jpg"></p><!-- This should be selected -->
<p>Hello world! <img src="bar.jpg"></p><!-- This should not -->

Any way to do this with CSS or jQuery? I've tried :first-child and :first-of-type but they match both of these elements.

Aucun commentaire:

Enregistrer un commentaire