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 trialLearning Coding
7,134 PointsWhy ul [0]?
If there is only one unordered list in the collection, why even need [0]?
2 Answers
Nathan Brenner
35,844 Pointsdocument.getElementsByTagName
returns a node list, or as Guil has said previously a collection of nodes, which is basically an array but they don't inherit directly from Array.
I agree, if you know that there's only one node that would match that query, then it might be better to use document.getElementByTagName
. I think Guil just used the alternative method to demonstrate the use more in this course.
Mars Epaecap
5,110 PointsMaybe he plans on adding more unordered lists later ?
Christopher Lebbano
15,338 PointsChristopher Lebbano
15,338 PointsIf you use javascript to link an element to a variable and it forms an array, even if there is only one index in the array you still have to specify with the [0] index.