CLiown
CLiown

Reputation: 13853

Set CSS based on child element

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?

Upvotes: 0

Views: 381

Answers (2)

user217782
user217782

Reputation:

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

You mean that?

Upvotes: 1

rahul
rahul

Reputation: 187110

Use .parent() selector.

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

Upvotes: 2

Related Questions