-1

Say a div has three child divs. I want to get the elements only if one of its children has specific class. Is it possible to do it with css?

Preethi
  • 1,434
  • 1
  • 13
  • 21

2 Answers2

0

This isn't possible with CSS alone. You will have to do some javascripting like this.. Replace selector classes with your own.

$(document).ready(function() {
    var hasChild = $('div.wrapper div.childClass').length >  0;
    if (hasChild) {
      // add specific class;
      $('div.wrapper').addClass('specific');
    }
});

Then you will be able to style the specific class;

Mark Rijsmus
  • 627
  • 5
  • 15
0

There is no parent selector in css but you can use jQuery if you want such kind of selector.

Try following code

$('div:has(> a.active)').css('background', 'red');

Check this DEMO

amol
  • 1,507
  • 8
  • 9