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 trialAdriana Ingwerson
4,115 PointsWhat 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?
1 Answer
brevans26
15,198 PointsHi!
See the hint? It reminds you that the getElementsByTagName
method 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
Adriana Ingwerson
4,115 PointsAdriana Ingwerson
4,115 PointsMakes complete sense thank you!