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 trialyaakov
2,381 PointsWhat'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
Full Stack JavaScript Techdegree Graduate 32,220 PointsHey 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");
Joseph Yhu
PHP Development Techdegree Graduate 48,638 PointsDo you know how to use querySelector()
to select a class? It's the same thing, except it's querySelectorAll()
instead of just querySelector()
;
yaakov
2,381 PointsHi 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
yaakov
2,381 Pointsyaakov
2,381 PointsThank you very much!
Kathryn Kassapides
9,260 PointsKathryn Kassapides
9,260 PointsI 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
Full Stack JavaScript Techdegree Graduate 32,220 PointsJason Miller
Full Stack JavaScript Techdegree Graduate 32,220 Pointshey Katheryn,
document.querySelector()
anddocument.querySelectorAll()
uses CSS selectors to select DOM elements. The.
in CSS is the class selector. SO in this example ofconst studentInfo = document.querySelectorAll(".student-info");
you're selecting all DOM elements with the class.student-info
. Hope that explanation helps.