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 Using CSS Queries to Select Page Elements

Why is it not explained?

Why in the first task of the challenge "Practice Selecting Elements" is given a challenge that it wasn't even explained here? In the challenge I was supposed to write document.querySelectorAll('nav a'); However, it's impossible to figure out that you need to add the "a", because it was never explained...

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Dinu Comendant! If you want to use the querySelectorAll() approach then you would need to understand CSS selectors. I see that by your profile, you don't yet have any points in CSS which would explain the source of the confusion. In the Teacher's Notes, you can find links to a course on CSS selectors and documentation. Because there are an infinite number of possible CSS selectors it would be impossible to show every combination.

That being said, there was another solution to this challenge that didn't involve querySelectorAll()

You could have also used the method shown several videos back and used that approach:

let navigationLinks = document.getElementsByTagName("nav")[0].getElementsByTagName("a");

This would get the first <nav> element and then from within that get all the <a> or "anchor" tags that define a link. There are multiple solutions to this problem. :smiley: The easiest and most common answer is to do a querySelectorAll("nav a"); but it is not the only answer.

Hope this helps! :sparkles: