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

Meg Dooley
Meg Dooley
7,321 Points

Practice selecting elements review challenge

I feel like I've tried every possible combination of selectors and i still can't get past the first challenge. Should I use the 'querySelectorAll' or am I supposed to amend the HTML document by adding a class or tag name?

4 Answers

Aakash Srivastava
Aakash Srivastava
5,415 Points

Hey Meg Dooley , here is the code :

// This will first select the "nav" tag and then  target all the "anchor" tag within it
let navigationLinks = document.querySelectorAll('nav a');
// This will first select the "ul" tag with id "gallery" and then target all the  "anchor" element within it
let galleryLinks = document.querySelectorAll('#gallery a');
// This will first select the "footer" element and then target all the "img" element within it
let footerImages = document.querySelectorAll('footer img');

Hope this helped :)

Hello Meg,

For the first task, since the challenge requires that we select the links which are in the nav element, you can use this:

let navigationLinks = document.querySelectorAll('nav a');

Here are some hints. But first review CSS Descendant Selector here

  • You shouldn't modify the html.
  • You should use querySelectorAll.
  • Make sure you select links (a not li). A lot of people make that mistake on this challenge.
Meg Dooley
Meg Dooley
7,321 Points

Thanks all!

I was going mad from overthinking everything!