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
  • 140,764
  • 31
  • 277
  • 265
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
  • 140,764
  • 31
  • 277
  • 265
Rahul Tripathi
  • 152,732
  • 28
  • 233
  • 299