0

Possible Duplicate:
Is there a CSS parent selector?

Say I have the following CSS:

<div class="div1">
    <div class="div2">
        <div class="div3">
            <ul class="div4">
                <li class="div5">

                </li>
            </ul>
        </div>
    </div>
</div>

Is there a way to target, if li.div5 then target .div1 so like change the background of .div1 if li.div5 ?

Community
  • 1
  • 1
Drew
  • 6,486
  • 16
  • 61
  • 95

4 Answers4

0
if($('li.div5').length) {
    $(this).parents('.div1')......
}
Diodeus - James MacFarlane
  • 110,221
  • 32
  • 151
  • 174
0

In pure CSS - No, I'm afraid there is no parent selector.

Chowlett
  • 44,716
  • 18
  • 112
  • 146
0

no, you can't with css only . there's not such selector working as an ancestor selector

Fabrizio Calderan
  • 115,126
  • 25
  • 163
  • 167
0

CSS cascades, so it only allows selection of children. There are no ascension selectors unless you implement something like jQuery and do it through javascript.

MetalFrog
  • 9,373
  • 1
  • 21
  • 23