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
Ryan Keon
1,743 PointsHelp with "Using Jquery to select Elements" task
Hi, I was hoping someone might be able to help me with the first code challenge in this course.
The part I'm stuck in is where it asks "On the next line, use jQuery to select all list items (li) in an unordered list (ul) with the class of 'nav'?".
I've tried several things, and double checked the various types of CSS selectors and all I can think of is that the code should be:
$(".nav ul li");
Am I missing something really silly? It's really bugging me and can't find the answer using google either. Would greatly appreciate a nudge in the right direction!
5 Answers
James Barnett
39,199 PointsThe 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?
deletedaccount
5,089 PointsThe reason that your code is wrong Ryan is because it's not actually selecting an unordered list with the class name of nav, it's selecting an unordered list inside an element with a class name of nav.
You want to append the class name onto the element, like this:
$("ul.nav li");
James Barnett
39,199 Points@Charles -
Here on the Treehouse forums we usually try to give a hint first and then wait for the asker to respond.
The goal of these forums is not to get people past a code challenge, instead it's to supplement learning so students of Treehouse solve their own issues.
If you take a look at posts from the Treehouse teachers you'll see them give several hints and rarely just give a correct answer to a code challenge.
deletedaccount
5,089 PointsHi, James.
I'm just trying to be as helpful as I can.
I can't find the forum rules anywhere, but if you can refer me and that actually is a policy, then thank you for telling me. But I've posted answers like these before and had teachers endorse them fully.
I know if I were as frustrated with my code not working as the askers must be, I would much rather have someone tell me where I went wrong than try to get my head around a cryptic answer. So I assume others are the same.
Anyway, where's Chalkers? Who is correct here?
Ryan Keon
1,743 PointsThanks for the replies Charles and James. I actually don't mind Charles response as he did quite clearly explain why the selector was wrong.
In fact I seem to have simply misunderstood the question. As James pointed out - I was trying to solve it with the assumption there was a div element named "nav" rather than the ul elements named "nav".
I do understand where you're coming from though James, as I realise that there isn't much point to learning if someone is simply giving you an answer without any explanation as to why that is the answer.
Thanks again to both of you for your help!