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 trialMax Toth
3,777 PointsWhat about const body = document.getElementsByTagName('body'); is incorrect as a method to retrieve and store <body>?
This is in reference to quiz question 1 for Javascript and the DOM after the section on retrieving HTML elements by various methods
1 Answer
Serban Lupea
7,432 Points.getElementsByTagName() method returns a live HTMLCollection of elements. So if you want to get the <body> you must specify its position in the collection/array like: document.getElementsByTagName(‘body’)[0] or use another method, document.querySelector(‘body’)
Ed Bundy
5,408 PointsEd Bundy
5,408 PointsI have the same question. It seems to me that this would yield the same thing as: document.getElementsByTagName('body')[0];
since there is only one <body> element
so why aren't they both correct answers? (It would only accept the latter).