Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74765

Using JQuery's find method, how do I select a sibling of some HTML element "foo", based on the content of a child of "foo"?

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 74765

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>