2

I have multiple DIVs of a specific class, and I want to select the one that contains an element with a specific ID. Example:

<div class="outerClass">
  <h3 id="firstId">My heading #1</h3>
  <p> My text 1</p>
</div>
<div class="outerClass">
  <h3 id="secondId">My heading #2</h3>
  <p> My text 2</p>
</div>
<div class="outerClass">
  <h3 id="thirdId">My heading #3</h3>
  <p> My text 3</p>
</div>

How can I select the DIV that contains the H3 with ID "secondId"?

Please note that I need to select the outer DIV that contains the H3 element, not the H3 element itself.

not2savvy
  • 2,902
  • 3
  • 22
  • 37
  • 1
    I don't think this is possible with css alone, at least not yet, in the future we'll be able to use :has https://caniuse.com/?search=%3Ahas I'd love to be proved wrong though – Jonas Grumann Jun 01 '22 at 09:32
  • 4
    checks here : https://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector – Romylussone Jun 01 '22 at 09:34
  • @Romylussone Thanks, my question actually seems to be a duplicate of it, but I had not found it before I posted my own. – not2savvy Jun 01 '22 at 09:41

0 Answers0