Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

What is the css selector for all li in an ul with the class nav ?

$("#container");

Then what?

8 Answers

James Barnett
James Barnett
39,199 Points

Assuming you are working on the code challenge Using jQuery to Select Elements


The key to this question is to understand that the <ul> element has a class of nav, in other words it's <ul class = "nav">.

So the HTML would look something like this:

<ul class="nav">
  <li></li>
</ul>

Now ask youself ... what is the CSS selector I would use to select all <li>s from the above markup?

ul.nav li

James Barnett
James Barnett
39,199 Points

To quote from another a great line in another recent thread ...

Its so easy just to copy and paste - but it'll catch up with you later down the road.

This is such an important point to understand, for anyone who replies to a question here on the forum.

The goal of these forums is to help each other understand how it works, not to get past a code challenge.

Thank you Charles for the code form I was looking for. After 30 minutes writing and entering bad code and getting "the red bar of durr." Frustration lead me to the forum, thank you for your help.

James thank you as well for helping me understand the thought process, that was exactly what I thought it might look like.

Luke Buśk
Luke Buśk
21,598 Points

Hmm...and why it is ul.nav li and not .nav li ? I think this is the only part i dont understand about "Making simple website".

Rick Yentzer
Rick Yentzer
5,885 Points

I have not taken that course yet but the difference between ul.nav li and .nav li is that the first one will select only li elements whose parent is a ul with the .nav class assigned to them whereas the second will select any li whose parent has the class .nav assigned to it.

In this case it looks to be redundant as the parent of a li item is going to be either a ul or ol.

Kirsty Pollock
Kirsty Pollock
14,261 Points

ah - bingo! I read the question to say that li had the class of nav ... hence me spendign much "red bar of 'durr...' " time...