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!
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
What did I type wrong to select the body by using document.getElementsByTagName?
My understand of the question is to tag the <body> from the html. So I wrote: const body = document.getElementsByTagName('body');
What did I do wrong?
See the hint? It reminds you that the
getElementsByTagNamemethod returns a collection.
What does that mean? It means that you can access the element through an index number.
For example, how many
body tags do you have on a page? One (normally).
So, since the question asks you to select the
body tag on the page using this method and knowing that this methods return a collection, you need to specify the index number of the selected element at the end of the method, like:
const body = document.getElementsByTagName('body')[index of the element]
Knowing that you have just one element, what is going to be your index number?
Hope I gave you hints enough without giving you the answer! haha