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

Michael Ramirez
Michael Ramirez
3,029 Points

how would you answer this?

How would you select the body element using document.getElementsByTagName, and store it in the variable body?

(Hint: Don't forget that this method returns a collection, not a single element.)

const body =

Gari Merrifield
Gari Merrifield
9,598 Points

It looks like they have basically given you the answer. If you are not understanding it, you may need to rewatch the videos, or look in the Teachers Notes, they probably have a link to the DOM reference at MDN.

This part may give you more clues : https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName

Michael Ramirez
Michael Ramirez
3,029 Points

ive already looked through that site, did not help. keeps saying the answer is wrong.

Gari Merrifield
Gari Merrifield
9,598 Points

And what did YOU try for your answer?

Tucker Blackwell
Tucker Blackwell
3,397 Points

I don't understand what you're getting at. Why not just select it with document.querySelector? Though I get that you're trying to ask a tricky question, there would literally be 0 use cases for using getElementsByTagName to select the body, so therefore, I think this question is pointless and doesn't really merit any deeper thought.

Gari Merrifield
Gari Merrifield
9,598 Points

Tucker : I think you are missing the entire point. This is a quiz question, not Michael's own.

Michael : It looks like this was covered previously on the forums : https://teamtreehouse.com/community/how-do-you-select-the-htmls-body-using-documentgetelementsbytagname

1 Answer

Tucker Blackwell
Tucker Blackwell
3,397 Points

Ohhhh. lol my bad. I wasn't actually working through this course I just got an email from Treehouse inviting me to answer random questions. I should have looked into it a bit more before answering. My apologies, Michael.