0

Possible Duplicate:
CSS :checked - change <td> background
Is there a CSS parent selector?

        <ul class="submenu">
        <li><a href="...">Submenu 3</a></li>
        <li><a href="..." >I need to select this element</a>
            <ul class="submenu">
            <li><a href="...">Sub-submenu 3</a></li>
            <li><a href="...">I need to select this element</a>
                <ul class="submenu">
                <li><a href="...">Sub-sub-sub 1</a></li>
                <li><a href="...">Sub-sub-sub 2</a></li>

Basically, I need to select every <li> element that is located BEFORE ul element with class="submenu" (ul class="submenu"'s parent)

I need to select this element

Community
  • 1
  • 1
Omar
  • 10,419
  • 21
  • 76
  • 106
  • 2
    That's not possible. You could (do something like) move `class="submenu"` to the `li`, and then you can just use `.submenu > ul` and `.submenu`. – thirtydot Jun 07 '12 at 13:49
  • @BoltClock why did you close my question? It is a duplicate to what? – Omar Jun 09 '12 at 20:14
  • 1
    There's a great big "Possible Duplicate" box up above that tells you. Not as great or big as the one down below, but, yeah. – BoltClock Jun 10 '12 at 01:14

2 Answers2

5

This is not currently possible with CSS alone. The functionality is currently being specced, but it won't actually be available for public use for quite some time (if ever).

 /* Only matches LIs with a UL.submenu descendant */
 li:has(> ul.submenu) {
  background:red;
 }

Note: The example provided is valid according to the current Editor's Draft, but the syntax may change or the functionality may be removed entirely before browser vendors even begin implementing it.

Originally taken from https://stackoverflow.com/a/10436066/526741

Community
  • 1
  • 1
0b10011
  • 17,120
  • 3
  • 62
  • 80
0

This is not possible. Your best option would be to use jQuery. That would give you many options to complete this task.

According to the link below it does look like CSS4 will have the ability to specifiy which element you would like.

Is there a CSS parent selector?

Community
  • 1
  • 1
kwelch
  • 2,172
  • 20
  • 22