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 trialChristy Kusuma
Courses Plus Student 4,563 PointsWhat is the answer?
How do I refer to a collection??? Isn't it just document.querySelector("#rainbow"); ?
3 Answers
Neil McPartlin
14,662 PointsThayer 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;
Thayer Y
29,789 PointsHi,
you can refer to a collection by using document.querySelectorAll()
its a method returns all elements in the document that matches
Thayer Y
29,789 PointsHi Neil McPartlin
Yes, you're right , 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
14,662 PointsNice solution ;-)
There are many ways indeed but I just wanted Christy Kusuma to know how close they were.
Christy Kusuma
Courses Plus Student 4,563 PointsOh wow this is interesting, you don't need the "#" before rainbow to call the ID???