0

I want to apply a rule on element1, if it contains element2. Is it possible?

<element1>

  ...

  <element2> ... </element2>

</element1>
Alex
  • 60,472
  • 154
  • 401
  • 592
  • Do you have PHP installed on your server? This could be accomplished with some simple regex. (Note that PHP is very simple to use, and can be cut and pasted into your code just like HTML/CSS/JavaScript. You don't have to recode your whole page, unlike other server languages like Perl) –  Dec 28 '12 at 02:56
  • 1
    instead of PHP, you can just use jQuery to do something like this as well. – kennypu Dec 28 '12 at 02:56
  • 1
    Only if you can wait for the [level 4 selectors](http://dev.w3.org/csswg/selectors4/#subject) ;-) – steveax Dec 28 '12 at 03:16

2 Answers2

3

No, there is no way to style a parent element. In CSS there is no operator like <. You can style only direct children with >, or descendants separating with a space.

For more, see a similar question Is there a CSS parent selector?.

Community
  • 1
  • 1
Eye
  • 7,902
  • 7
  • 40
  • 68
1

this is only posible with Jquery

than you need to use something like this

    $("div").each(function(){

            if(jQuery(this).attr('class') != undefined && jQuery(this).hasClass('myclass')) {
              jQuery(this).css({"background-color":"green"});
         } else {
              jQuery(this).css({"background-color":"red"});
         }
    });​
Ivo
  • 2,368
  • 6
  • 21
  • 41