I want to select an element if and only if its adjacent sibling is a certain element.
<div>
<h1>Select Me</h1>
<h2>I'm the sibling, yay!</h2>
<div>
<p>A paragraph.</p>
</div>
</div>
<div>
<h1>Don't Select Me - I have no h2 sibling. :(</h1>
<div>
<p>A longer paragraph.</p>
</div>
</div>
In this particular example, I only want to select the first h1
because it has an adjacent h2
. The other h1
doesn't meet that criteria so I don't want it selected.
I found this but it won't work for me because the element has other siblings and is never an only child.
always appear first in its parent element? You might be able to use :first-child, but that's kind of a big assumption on my part.
– Taconut Apr 07 '16 at 20:58