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

I need help understanding use querySelectorAll to obtain a reference to all elements in a document with the class --?

I'm stumped and have watched the video over several times and reviewed my notes. What is this asking? I've tried the same methods they used in the video and none of them have worked.

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 = ___________

12 Answers

Steven Parker
Steven Parker
231,007 Points

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

I am really terrible with JS... Literally doing everything wrong. 3 y.o can probably out do me on this. Idk what it is about it that's so difficult.

THANK you.

Thanks so much!

I did exactly the same, except the semi-column at the end...really treehouse, this is not critical. I would work with or without the ";"

Thank you and have a blessed day.

Cam Brennan
Cam Brennan
12,350 Points

it doesn't seem to like single quotes like this: document.querySelectorAll('.student-info'); it will only accept document.querySelectorAll(".student-info");

Thank you, have a blessed day.

I had the same issue. I followed exactly what Guil did in the video:

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

and it didn't pass, but the answer from @stevenparker worked just fine. Anyone know why this is the case?

Brooke Smart
Brooke Smart
10,763 Points

The . class distinction is missing ('.student-info')

Jack Cummins
Jack Cummins
17,417 Points

It’s because you used single quotes instead of double quotes also .

Mike Hatch
Mike Hatch
14,940 Points

I also made the mistake. It's the period before "student" that we're overlooking.

I tried also with the single quote, should work as well I believe but not here...

Tyler Kesling
Tyler Kesling
6,905 Points

I've tried both const studentInfo = document. querySelectorAll(".student-info"); const studentInfo = document. querySelectorAll('.student-info');

neither are passing today.

I am having the same issue??

ian truong
ian truong
4,685 Points

what do we do ? document.querySelectorAll(".studentInfo"); does not work.

document.querySelectorAll(".student-info"); worked for me. I had similar issues with the single quotes, but this seems to require double quotes

Had issues with this one because I was answering the quiz on my tablet instead of my laptop. Steven's example is correct.

I think this could be help . const studentInfo = document.querySelectorAll('.student-info'); It works.

const studentInfo = document.querySelectorAll('.student-info')

the above works well

Julieta Dalla Pozza
Julieta Dalla Pozza
4,337 Points

thanks! but why? in the video they dont specify that we need dots for classes and # for ids right?

Julieta Dalla Pozza
Julieta Dalla Pozza
4,337 Points

thanks! but why? in the video they dont specify that we need dots for classes and # for ids right?