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

shekhar bhardwaj
seal-mask
.a{fill-rule:evenodd;}techdegree
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 Points

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.

Ezell Frazier
Ezell Frazier
22,110 Points

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.

shekhar bhardwaj
seal-mask
.a{fill-rule:evenodd;}techdegree
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 Points

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