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 trialSamuel Joseph
5,406 PointsHow can one solve this question? I used document.getElementsByTagName('body');
Is there some alternative way that I should write this?
1 Answer
Matthew Long
28,407 PointsYou're almost right. Except, if you notice, the function is getElementsByTagName()
not getElementByTagName()
. Elements is plural. This is a good indication that it will select a collection of elements, not just a single element. In this case, you want to select the first body, which would be the first index in this collection:
const body = document.getElementsByTagName('body')[0];