0
<div class="first">
    <div class="a">
        <div class="b">
            <div class="c">
            </div>
        </div>
    </div>
</div>
<div class="first">
    <div class="one">
    </div>
</div>

I want to style div with class="first"(i.e,(2) from above) if there is a div with class="c".

Context: Here the div with class="c" will be dynamically generated,so if this div exits i want to apply css for div with class="first"(i.e,(2) from above). What could be the css rule for the above case?

Ajay Makwana
  • 2,330
  • 1
  • 17
  • 32

1 Answers1

1

You would need to use jQuery.

$(window).load(function() {
  $('.c').parents('.first').addClass('selected');
});
/* DEMO */

div {
  padding: 1em;
  background: green;
  border: solid 1px;
}
div:nth-of-type(odd) {
  background: yellow;
}
/* ADDED CLASS */

div.selected {
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="first">
  <div class="a">
    <div class="b">
      <div class="c">
      </div>
    </div>
  </div>
</div>
<div class="first">
  <div class="one">
  </div>
</div>
Aaron
  • 10,187
  • 3
  • 23
  • 39