1

Say I have the following mark up

<div class="xxx yyy zzz"> <!-- This div is generated by JS and the class names change all the time -->
   <div class="aaa"> Hello </div>
</div>

How can I target the css of the parent div without knowing the class name of the parent div using CSS only ?

Ex: parent.aaa { background: #fff; }
user1038814
  • 8,281
  • 14
  • 56
  • 84

2 Answers2

1

It's not possible to target a parent of an element with CSS. Would be nice!

You could use javascript to find the element and then add a class to the parent, then style that added class:

// javascript - jquery
$(".aaa").parent().addClass("parentClass");

// css
.parentClass {
    ... your styles ...
}
Tim Kindberg
  • 3,555
  • 1
  • 23
  • 26
0

In CSS there are no parent selectors, but you can use Javascript

element.parentNode