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

JavaScript

Deleted User

Can you tell me why this isn't right? (Introduction to jQuery --> Using jQuery to Select Elements)

Question: "On the next line, use jQuery to select all list items (li) in an unordered list (ul) with the class of 'nav'?"

$("#container"); $("ul li .nav");

3 Answers

The reason your code doesn't work Alan is because that selector is selecting elements with the nav class name, inside a list item, inside an unordered list.

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

If that was your code, the span element would be selected. But the nav class name should be on the unordered list, not inside the list item.

So this is the code you want:

$("ul.nav li");
James Barnett
James Barnett
39,199 Points

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?

Deleted User

Thank you both very much! That is crystal clear for me now.