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

Introduction to jQuery > Using jQuery to Select Elements

Having a problem with a seemingly simple piece of code. I'm new to jQuery and it seems quite straight forward, but no matter what I try I can't seem to get passed this code challenge. The question is as follows:

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

And this is my code:

 $(".nav ul li");

For the heck of it I tried .nav at the end,as well as removing the class identifier as if it were a CSS3 nav element amongst other things, but to no avail. Any help would be appreciated. I'm probably going to be kicking myself, haha.

16 Answers

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

All LI in UL $('ul li');

where the UL has CLASS = nav

$('ul.nav li');

Hi Paul,

I'm not sure. I haven't reached that bit yet. But, the language used to refer to it seemed logical IF you are used to working with CSS selectors, regularly.

I read it as: a) Select LI elements

  • $('li'); b) in a UL
  • $('ul li'); c) with a class ("with" referring to the UL or LI):
  • $('ul.nav li') OR $('ul li.nav');

However, since you wouldn't normally mark a list item element with a navigation class separately from the other list item elements within the same unordered list, I assumed the 'nav' class belonged to the UL element.

But, I haven't reached that yet to know if there's a better way to have written it in the context. What's the course link?

Thanks, Andrew

I never even thought of piecing it together like that, with the way I was interpreting the question, thanks a lot Andrew!

My pleasure Jordan :)

Thanks for the help. I don't see any possible way someone could have figured this out without the help of the forum. This isn't covered in the video, and there doesn't seem to be a reference out there.

Am I missing something?

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

How to compose CSS selectors aren't covered in this video. How to select elements with jQuery using CSS selectors are.

This challenge is designed to see how comfortable you are with CSS. If you find yourself struggling with CSS it may be an idea to take a look at the deep dive in to CSS by Guil.

Hi Andrew, very good point :)

That is excellent advice Andrew. Thank you for the incredibly fast response.

I made the jump straight from the Responsive plan to the Interactive plan. I hadn't even considered the deep dives.

I'll start on those now!

Kind Regards

:)

James Barnett
James Barnett
39,199 Points

@Paul - JQuery comes at the end of an 8 course sequence.

Check out the Become a Web Designer learning adventure to see the order in which the courses were designed to be completed in.

That's awesome, thanks James - I just joined.

That order makes much more sense to me.

This is a great forum!

James Barnett
James Barnett
39,199 Points

@Paul - It's a common mistake that new members make.

Jonathan Leopard
Jonathan Leopard
6,919 Points

I was stuck on this one as well. Thanks for the help guys

Hello there,

I have tried: $("ul.nav li"); and $('ul.nav li');

none of these are working, please help, I'm getting frustrated!

Thanks

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Hey Mauricio,

What OS are you on?

Regards Andrew

I'm on a mac OSX and it doesn't accept $("ul.nav li"); and $('ul.nav li');

Regards,

S

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Can you take a screenshot of it not working and send it to help@teamtreehouse.com?

Regards Andrew

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Are doing it on the next line like this?

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

I pass the Code Challenge with no issues.

I deleted the $("#container"); , that was the real problem. Heh

Tech Solutions
Tech Solutions
6,077 Points

this is a badly composed question, it's very easy to think that you mean li elements with the class of nav rather than the ul having it