9

Possible Duplicate:
Is there a CSS parent selector?

I am able to hide a DOM tree which look in this way by using .closest().

<div class='parent'>
  <!-- some html code -->
  <div class='child'>
  </div>
  <!-- some html code -->
<div>

$('.child').closest('parent').hide();

It will be possible to get the same effect just by using CSS?
If yes, how?

Community
  • 1
  • 1
Lorraine Bernard
  • 11,982
  • 21
  • 79
  • 132

3 Answers3

3

No selector currently exists that can select a previous or parent element.

There is a level 4 selector that is currently being developed.

So in the future, you may be able to do something like this:

!.parent > .child { display: none; }

But until then, you'll have to stick with

$('.child').parent();

in jQuery.

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
Matt Kieran
  • 3,924
  • 1
  • 14
  • 15
2

No. See for yourself, no such selector exists in CSS3, and not in CSS2 either.

Josh Davenport
  • 5,308
  • 2
  • 25
  • 40
-6

Might be able to use this

.child:parent .parent{display:none;}

http://css-tricks.com/parent-selectors-in-css/

Josh Bedo
  • 3,092
  • 3
  • 19
  • 31