0
<div> /*i want to select */
     <div>
           <div class="ui-message-error">
           </>
     </div>
</div>

I have a page something like that and i can not appoint class parent divs. So how can i select parent div if child of child of that div has 'ui-message-error' class.

4 Answers4

0

I beleive that in CSS that is not possible, you can either do it the other way around and select the child of 'ui-message-error' or do it with javascript.

Overlugged
  • 39
  • 8
0

If it's a direct child of a parent (for example the body) you could use body > div { }

If the div has a specific preceding element, for example:

<div id="specificDiv"> bla </div>
<div>
     <div>
           <div class="ui-message-error">
           </>
     </div>
</div> 

You could use #specificDiv + div { }.

If you are looking for a way to select the div based on the class of the child, you'll need a Javascript solution

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
0

Using jQuery you can do like this:

jQuery(document).ready(function(){
   jQuery('.ui-message-error').parent().parent().css('display','none');
});
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0

You cant do it with CSS, but if you use jQuery it is possibele like this:

$(".ui-message-error").parent().parent().addClass('myparent');

DEMO : http://jsfiddle.net/fcrDX/


Your code could go like this:

HTML:

<script src="http://code.jquery.com/jquery-latest.js"></script>

<div> /*i want to select */
 <div>
       <div class="ui-message-error">
       </div>
 </div>
</div>
<script language="javascript">
$(function() {
    $(".ui-message-error").parent().parent().addClass('myparent');
});
</script>

CSS:

.myparent{
    border:1px red solid;
}
naota
  • 4,695
  • 1
  • 18
  • 21