-1

I tried searching for option to apply css to parent div but failed to achieve it. I finally implemented the same with jquery. Do we have any option for the below jquery line to implement with css

 $('.description').parent().prev().closest('div').css('padding-top', '10px');
Kurkula
  • 6,673
  • 23
  • 99
  • 170

2 Answers2

1

Currently no, there is not. This is similar to a previous thread -
Is there a CSS parent selector?

However, you could just apply a class or id to your parent and select it in CSS using that newly set class/id.

Community
  • 1
  • 1
johnsoe
  • 624
  • 1
  • 5
  • 13
0

Assuming your html looks a bit like this:

<div>
   <div class="description">
          ............
   </div>
</div>

Then the jQuery to target the parent of 'description' would be:

$('.description').parent().css('paddingTop', '10px');

Fiddle here: http://jsfiddle.net/EFmf8/ (changes colours instead of padding to better illustrate)

Pity there's no CSS selector for this . . .

Pat Dobson
  • 3,086
  • 1
  • 14
  • 30