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 DOM Selection - More Review

What's the correct answer?

How would you use querySelectorAll to obtain a reference to all elements in a document with the class student-info and assign it to the constant studentInfo?


const studentInfo = _________

Why it's impossible to see a correct answer when I don't know it?

2 Answers

Jason Miller
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Miller
Full Stack JavaScript Techdegree Graduate 32,220 Points

Hey Yaakov, document.querySelector() and document.querySelectorAll() uses type and/or css selectors to select elements on a webpage. So the answer for this question would be:

const studentInfo = document.querySelectorAll(".student-info");

Thank you very much!

Kathryn Kassapides
Kathryn Kassapides
9,260 Points

I had the same answer except I didn't have the dot before student-info. Why is it .student-info and not just student-info?

Jason Miller
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Miller
Full Stack JavaScript Techdegree Graduate 32,220 Points

hey Katheryn,

document.querySelector() and document.querySelectorAll() uses CSS selectors to select DOM elements. The . in CSS is the class selector. SO in this example of const studentInfo = document.querySelectorAll(".student-info"); you're selecting all DOM elements with the class .student-info. Hope that explanation helps.

Do you know how to use querySelector() to select a class? It's the same thing, except it's querySelectorAll() instead of just querySelector();

Hi Joseph, thank you for your answer. Yes I'm trying to "use querySelectorAll()" in this way:

const studentInfo = document.querySelectorAll();

but I'm not sure what I should to put in the parenthesis. What is the solution?

Thanks