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 Selecting Multiple Elements

Christy Kusuma
PLUS
Christy Kusuma
Courses Plus Student 4,563 Points

What is the answer?

How do I refer to a collection??? Isn't it just document.querySelector("#rainbow"); ?

3 Answers

Neil McPartlin
Neil McPartlin
14,662 Points

Thayer is correct in what he says but for this challenge, there is only one 'unordered list' in the html bearing the ID 'rainbow' so document.querySelector("#rainbow"); is good enough for selecting the 'parent element' of the list. But you need the actual individual list elements i.e. the children.

Therefore this will work...

let listItems = document.querySelector("#rainbow").children;

Hi,
you can refer to a collection by using document.querySelectorAll() its a method returns all elements in the document that matches

Hi Neil McPartlin
Yes, you're right :thumbsup:, but there are many ways to select all list items in the unordered list element with the id of "rainbow", for instance, you can select like this way also

let listItems = rainbow.children;

and it will work

Neil McPartlin
Neil McPartlin
14,662 Points

Nice solution ;-)

There are many ways indeed but I just wanted Christy Kusuma to know how close they were.

Christy Kusuma
Christy Kusuma
Courses Plus Student 4,563 Points

Oh wow this is interesting, you don't need the "#" before rainbow to call the ID???