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

What am I doing wrong here?

const body = document.getElementsByTagName('body')[0]

I am searching all the elements with tag name body and I am taking the first element from the list and assigning it to a constant variable.

What is the objective of your project?

Based on what you've provided, the body variable will contain the <body> HTML element.

The const statement will prevent reassignment of the variable, but you'll still be able to append, add/ remove attributes, or remove the element from the DOM entirely if you choose.

Ezell Frazier Thanks, Ezell, It was one of the quiz questions, the same code worked after a while mystifying but my answer was right could be a glitch when I was trying earlier, thanks again for looking into it.

1 Answer

const body = document.getElementsByTagName('body')[0] worked after a while, could be a glitch when I was trying.