petko_stankoski
petko_stankoski

Reputation: 10713

CSS set style to the parent of class="something" tag

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>

Upvotes: 1

Views: 1666

Answers (3)

Simone
Simone

Reputation: 21262

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.

Upvotes: 0

haynar
haynar

Reputation: 6030

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

Upvotes: 0

Jason Gennaro
Jason Gennaro

Reputation: 34855

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

Upvotes: 2

Related Questions