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

using document.querySelectorAll

please can i get help on using document.querySelectorAll on the student info question on javascript and the dom

1 Answer

Hi Malcolm Mowlam,

The querySelector and querySelectorAll methods use CSS selectors to define which elements to select. They work in the same way except the querySelector method only returns the first element that matches the selector passed as an argument, while querySelectorAll returns a nodelist of all the elements that match the selector passed as an argument. Furthermore, the querySelectorAll method returns a nodelist EVEN if only one element matches the selector. You can read up a bit on nodelist at develop.mozilla.org.

Here’s a link to an mdn article on document.querySelectorAll: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

If you don’t have any experience with CSS just yet, I would suggest googling “css selector for a class” to figure out how to write the selector you’ll pass into document.querySelectorAll.

Hope this helps. If not, let me know.