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

Simon Lovelock
Simon Lovelock
5,537 Points

Just starting JQuery

Hi Guys just starting jQuery and hit an issue with the first challenge....

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

========================== My code:

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

========================== not sure what is wrong, any help would be great.

Thanks in advance.

5 Answers

James Barnett
James Barnett
39,199 Points

The key to this question is 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?

Simon Lovelock
Simon Lovelock
5,537 Points

From your response i am now thinking i no longer need the <ul> identifier then and therefore my code becomes:

$(".nav li");

however this does not work either, i'm thinking i am missing something very obvious.

Simon Lovelock
Simon Lovelock
5,537 Points

Ahhhh it's ok, i've got it now and understand where i was going wrong.

Thanks for you help James.

Si.

James Barnett
James Barnett
39,199 Points

@Simon - Great job on figuring that out :smile:

That's probably the most asked question about a code challenge on the forum.

The way the questions are phrased sometimes - they're like word problems. But that's OK.