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 trialRazvan Chirca
9,945 PointsHow do i solve the first task from the last challenge from "JavaScript and the Dom"
In the following tasks you'll be required to select various elements on the index.html page. In the app.js file on line 1, select all links in the nav element and assign them to navigationLinks.
3 Answers
Steven Parker
231,271 PointsThe easiest way to do this is probably using querySelectorAll.
You might want to review the Using CSS Queries to Select Page Elements video where this was introduced.
Remember when constructing the query string that "links" are actually "a
" elements, so a descendant selector for links within a nav
element would be "nav a
".
Thomas Fildes
22,687 PointsHi Razvan,
The below code will allow you to pass the first task in the challenge:
let navigationLinks = document.querySelectorAll('nav a');
The above code allows you to select all links (a) inside the nav element, hence ('nav a')
Hope this helps... Happy Coding!!!
Jamal Shiekh
6,440 Pointslet navigationLinks = document.querySelectorAll('nav a');
let galleryLinks = document.querySelectorAll('#gallery li a');
let footerImages = document.querySelectorAll('footer img');