"JavaScript Basics (Retired)" was retired on March 27, 2020.

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 Selection Review

Shawna Carey
Shawna Carey
3,691 Points

Not sure why my answer is incorrect. Is 'body' not the name of the tag?

I know that document.getElementsByTagName returns an HTML collection to the body variable listed. I put 'body' as the tag to grab, but it is saying my answer is incorrect.

2 Answers

You're right, body is a tag name - the key here is the hint on the question, which says that getElementsByTagName returns a collection. There might only be one body, but if you selected another element tag like h1, there could very well be multiple, which is why a collection is returned, even if there's only one match.

It should pass if you add [0] to indicate the item at index 0 - document.getElementsByTagName('body')[0]

Shawna Carey
Shawna Carey
3,691 Points

Thank you for your response!

document.getElementsByTagName('body') returns an array.

document.getElementsByTagName('body')[0] returns the body html.

Play around with it in the Chrome Developer Tools console!