I want to apply a rule on element1, if it contains element2. Is it possible?
<element1>
  ...
  <element2> ... </element2>
</element1>
I want to apply a rule on element1, if it contains element2. Is it possible?
<element1>
  ...
  <element2> ... </element2>
</element1>
 
    
    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?.
 
    
     
    
    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"});
         }
    });
