2

I have html like this:

<div class="first"> <div class="second home"> </div> </div> <div class="first"> <div class="second"> </div> </div> 

Is it possible to style div element with class first if child div has home class?

2
  • As of now No. It will be possible in css4... in future. Commented Jan 9, 2014 at 12:04
  • 1
    this feature is upcoming in CSS, See ref: css-tricks.com/parent-selectors-in-css Commented Jan 9, 2014 at 12:30

2 Answers 2

1

Can do it using jquery

$($('.home').parent('div')).addClass('first'); 
Sign up to request clarification or add additional context in comments.

Comments

0

try something like this

$('.home').parent('div').addClass('first'); 

All child element with home than

 $('.home').each(function(){ $(this).parent('div').addClass('first'); }); 

1 Comment

each loop is not required here...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.