0

I have this in my HTML file:

<td>
    <div class="something">someText</div>
    <div class="something">otherText</div>
</td>

Is there a way in CSS I can set the background of the PARENT of the class named something? In this case, the tag?

Here is my code:

    <script type="text/javascript">
       function MyMethod(sender, eventArgs) {
           if (condition) {
               app.set_cssClass("MyClass");
           }
           $('.MyClass').parent().css('background', 'url(Images/star.png) no-repeat')
        }
    </script>
Charles
  • 48,924
  • 13
  • 96
  • 136
petko_stankoski
  • 9,682
  • 37
  • 116
  • 215
  • 1
    Possible duplicate of http://stackoverflow.com/questions/3777379/can-we-set-parent-element-style-from-child-style – chrisfrancis27 Dec 19 '11 at 13:46
  • possible duplicate of [CSS Parent/Ancestor Selector](http://stackoverflow.com/questions/1251768/css-parent-ancestor-selector) – Wesley Murch Dec 19 '11 at 13:50
  • possible duplicate of [Is there a CSS parent selector?](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – Yi Jiang Dec 19 '11 at 14:16

3 Answers3

2

At this point, no.

However, jQuery can do this quite easily.

$('.something').parent().css('//WHATEVER')

In the future, CSS4 will be adopting a subject selector, which would do what you need

$OL > LI:only-child

The $ would be used to select the parent or subject of a specific element.

http://www.w3.org/TR/selectors4/#subject

Jason Gennaro
  • 32,917
  • 6
  • 59
  • 84
0

no, as I know there is no parent selector in CSS

haynar
  • 5,708
  • 7
  • 29
  • 53
0

No, but you can do it in jQuery

$('.something').parent().css('background','<rules>')

Where <rules> are the CSS rules you want to set for the background property.

Simone
  • 17,439
  • 10
  • 67
  • 96