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

Scott Shanley
Scott Shanley
4,309 Points

Looking for some help here. Tried everything, and can't move on without an answer...

Not sure if I'm just confused by the wording here or if it's something really simple i'm just overlooking. Super frustrating since I can't just see the answer after getting it wrong a thousand times.

Michael Hulet
Michael Hulet
47,912 Points

Could you post the code you've written so far here? It makes it a bit easier for us to help you out 🙂

Scott Shanley
Scott Shanley
4,309 Points

Been playing around with a bunch of different variations of the below.

let navigationLinks = document.getElementsByTagName('nav ul li');
let galleryLinks;
let footerImages;

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

It looks like you actually have the basic gist of this, but I see 2 issues:

  1. You have the right idea that the easiest thing to do here would be to reference the elements by a CSS selector, but the getElementsByTagName function only takes the name of a single kind of tag and returns an array of all elements of that tag in the page. In order to query the DOM using a CSS selector, you need to use the querySelectorAll function, which takes a CSS selector as an argument and returns an array of all elements matching that selector
  2. You're selecting the wrong elements with your CSS selector. This step of the challenge asks you to select all links within the nav tag, but your selector targets all list items in an unordered list in the nav tag. I know it's fairly counterintuitive, but in HTML, a link is actually represented by the a tag

Once you take care of those 2 issues, I think you'll be on the right track for this challenge. Great job!

Scott Shanley
Scott Shanley
4,309 Points

Got it! Thank you for your help and quick response!