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

Code Challenge: Task 2 of 2 Using jQuery to Select Elements

I thought this challenge seemed simple enough but I cannot seem to pass.

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

I wrote: $(".nav ul li");

I have tried many other combinations that would be too numerous to list. What am I missing?

5 Answers

Liz -

Try $("ul.nav li") - that will match all list items inside of any unordered list with a class of "nav". What you have is "all list items inside any unordered list which is inside any element that has the nav class".

Remember that jQuery selectors go in hierarchy order, and spaces denote new elements. If you're looking for a ul with a class of .nav, it needs to be ul.nav (no spaces).

Hope that helps!

Yes that worked! Thanks so much.

You're most welcome :)

Hi Liz,

Try this hint first. I'll post the answer in a separate post.

In css, how would you select an unordered list (ul) with the class="nav" ?

Okay how would select the list items (li) that are descendants of an unordered list with a class ="nav"?

Nevermind. You got it.