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 trialshekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 PointsWhat 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.
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 PointsEzell 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
shekhar bhardwaj
Full Stack JavaScript Techdegree Student 12,373 Pointsconst body = document.getElementsByTagName('body')[0] worked after a while, could be a glitch when I was trying.
Ezell Frazier
22,110 PointsEzell Frazier
22,110 PointsWhat 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.