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 JavaScript and the DOM (Retiring) Getting a Handle on the DOM Practice Selecting Elements

Natanon Bay
Natanon Bay
5,218 Points

I keep getting 5 links not 3

I am getting 5 links instead of 3 no idea why and i get lost trying to figure out whats going on in the index.html. I feel like the solution is very simple but i cant get it HELP!

Steven Parker
Steven Parker
231,248 Points

Please show your code to make it possible to identify the issue.

3 Answers

Steven Parker
Steven Parker
231,248 Points

Glad I could help. Happy coding!

Steven Parker
Steven Parker
231,248 Points

I can't be specific without seeing your code, but most likely your selector is not specific enough. The challenge asks for "all links in the nav element", so depending on what method you use, you'll need chained methods or a descendant selector.

Natanon Bay
Natanon Bay
5,218 Points

first I tried let navigationLinks = document.querySelectorAll('li'); but realized there were 2 extra so i tried let navigationLinks = document.querySelectorAll('nav'); hoping it would select all the links in the nav element but i only got 1 link. I also tried let navigationLinks = document.getElementsByTagName('nav');

Steven Parker
Steven Parker
231,248 Points

But "li" is a list item, and "nav" by itself would only target the nav element itself.

A "link" is represented by an "a" element. So to get all the links inside the nav you could use a descendant selector: "nav a".

Natanon Bay
Natanon Bay
5,218 Points

Okay thank you so much i got it!