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,206
  • 15
  • 58
  • 93

4 Answers4

0
if($('li.div5').length) {
    $(this).parents('.div1')......
}
Diodeus - James MacFarlane
  • 107,156
  • 31
  • 147
  • 171
0

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

Chowlett
  • 42,941
  • 17
  • 109
  • 142
0

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

Fabrizio Calderan loves trees
  • 109,094
  • 24
  • 154
  • 160
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
  • 8,525
  • 1
  • 20
  • 23