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

Carel Du Plessis
PLUS
Carel Du Plessis
Courses Plus Student 16,356 Points

I don't understand why my code is not working.

Challenge question

On line 3 of app.js, select all images in the footer element and assign them to footerImages.

let footerImgs = document.querySelector('footer'); let footerImages = footerImgs.querySelectorAll('a');

why can't I use document.querySelector('footer') to select the footer tag and then use footerImgs.querySelectorAll('a') to select all the links inside the footer.

Challenge question

On line 3 of app.js, select all images in the footer element and assign them to footerImages.

let footerImgs = document.querySelector('footer'); let footerImages = footerImgs.querySelectorAll('a');

second try

in the console when i run document.querySelector('footer > a');

the console prints: NodeList(2) [a, a]

let footerImgs = document.querySelectorAll('footer > a'); let footerImages; for (let i = 0; i < footerImgs.length; i += 1){ footerImages[i] = document.querySelectorAll('footer > a')[i]; }

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Can you please use markdown so that we can understand you code better .
Just surround your code with ' ``` ' ( triple backticks) Thanks

3 Answers

Steven Parker
Steven Parker
231,248 Points

The instructions say "select all images in the footer element and assign them to footerImages."

But your code is selecting all the links (a) in the footer element instead of the images (img).

Fix that, and your first try will work.

Gonzalo Torres del Fierro
PLUS
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Points

This line will select all images in the footer element (whether they are direct descendants or not) and assign them to the variable footerImages

this is a Jenifer Nordel Solution share with me on Slack