JavaScript JavaScript and the DOM Getting a Handle on the DOM DOM Selection - More Review

yaakov
yaakov
2,013 Points

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
Front End Web Development Techdegree Graduate 22,570 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");
yaakov
yaakov
2,013 Points

Thank you very much!

Jason Miller
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Miller
Front End Web Development Techdegree Graduate 22,570 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.

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 46,902 Points

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

yaakov
yaakov
2,013 Points

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