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

Trouble With jQuery

Hi, some please assist me. I can't seem to figure out what's wrong with my code. Am i doing something wrong?

Code Screen Shot

Screen shot

6 Answers

J.T. Gralka
J.T. Gralka
20,126 Points

Zablon,

This one's a little bit tricky! The way I'd go about this is like so:

$("ul.nav li");

In other words, I'm selecting an unordered list with the class nav and selecting the list items associated with that unordered list. Does that make sense? It's a little bit weird, I know.

Let me know if you need any more explanation, and if it still doesn't click, try emailing help@teamtreehouse.com. Maybe Andrew or another one of the teaching staff would be able to explain it better than I could.

Best of luck!

J.T.

James Barnett
James Barnett
39,199 Points

@Zablon

+1 To what @Charles said, I would add ...

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?

James Barnett
James Barnett
39,199 Points

@JT - Here on Treehouse forums the goal is not to get people past a code challenge, instead it's to supplement learning so students of Treehouse solve their own issues.

Your explanation is great, if after reading that the student still needs more help give maybe give them a hint on where to look in their code for 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.

J.T. Gralka
J.T. Gralka
20,126 Points

Point very well taken, James! I definitely agree with what you're saying. I generally try not to blatantly give away answers. Perhaps I was a bit too overzealous with this one... :-/ Zablon, considering that I definitely spilled the beans right there, you should know that I didn't mean to spoil your learning experience!

The point of my post wasn't to give you a correct answer to the code challenge; I wanted to demonstrate that there are other ways of composing jQuery constructors, and I don't know if Andrew covered that specific method in the video (I could be very wrong, though). Hopefully my explanation makes sense, and again my apologies for letting the cat out of the proverbial bag. In retrospect, that wasn't very constructive of me!

J.T.

Thank you very much for your help J.T to be honest that would have taken me a while to figure out.

Hi James thank you to for the hint but from what i have been able to learn is that i can and should be able to call an element using only its class or id without having to call the specific element itself. That is where i think the problem is because Up until the example given by James, I honestly wasn't aware that you could write code like that.

None the less thank you for all you help guys. lesson well learnt.

James Barnett
James Barnett
39,199 Points

@Zablon - Have you gone through the CSS deep dive course yet? If not now might be a good time to review your CSS selectors.

You can also check out the Selectutorial to brush up CSS selectors