views:

34

answers:

2

I have the following nav:

<div id="nav">
<div id="subnav">
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
</div>
</div>

The following jQuery:

$('#subNav:not(:has(a))').css('background','none');

So #subNav's background is 'none' when its empty.

I also want to set $nav background to 'none' at this point, some kind of and??? How can I do this within this same function?

+2  A: 

Use .parent() selector.

$('#subNav:not(:has(a))').css('background','none').parent().css('background','none');
rahul
+1  A: 
$('#subNav:not(:has(a))', '#nav').css('background','none');

You mean that?

Rygu
He wants to set the `#nav` background to none only when the first selector matches. I guess your selector will do it every time irrespective of match. Correct me if I am wrong.
Teja Kantamneni