Suppose I have HTML like the following:
<div class="foo-container">
<div class="foo">
<div class="foo-child">
<span>The Important Label</span>
</div>
</div>
<div class="elem-to-manipulate">
<p>I want to manipulate the style in this because it's the sibling of "The Important Label"</p>
</div>
</div>
How can I target that p
element, based on the fact that its sibling has the text The Important Label
.
I got to something like
$('.root').find('.foo > .foo-child > span:contains("The Important Label")')
which successfully gets me the span
element. But now how do I get the p
element in the sibling div
? Is there some way to tell find which parent to get the sibling of ?