0

Say I have:

<div class="thing">
    <a>hi</a>
    <span class="poo">
        <p id="hello">my name is</p>
    </span>
</div>

<div class="thing">
    <a>hi</a>
    <span class="poo">
        nothing to see here
    </span>
</div>

I want to select the first div, but only because it has a p#hello inside it.

Mr. Alien
  • 147,524
  • 33
  • 287
  • 271
user104323
  • 45
  • 1
  • 5

1 Answers1

3

With pure CSS it is not possible, you may try to use Jquery and try using :has() selector

The expression $( "div:has(p)") matches a <div> if a <p> exists anywhere among its descendants, not just as a direct child.

Mr. Alien
  • 147,524
  • 33
  • 287
  • 271
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319