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
ammarkhan
Front End Web Development Techdegree Student 21,661 PointsHow would you select the body element?
In Javasript and DOM course, there is a quiz question which says How would you select the body element using document.getElementsByTagName, and store it in the variable body?
const body = ______________
I am confused on how would i write the answer to the mentioned above question?
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are close. getElementsByTagName() is a method, you are calling it on document and storing the return in a constant called body. you call the method with the argument of the element you want, so body, as a string ('body').
William Siewert
9,448 PointsHere is what the code should look like.
const body = document.getElementsByTagName('body');
Here is also a link to show you CSS selectors for future reference when you get stuck. https://www.w3schools.com/cssref/css_selectors.asp
William Siewert
9,448 PointsThe CSS selectors really only pertain to querySelector seeing how getElementsByTagName is strictly for the HTML element tag name. Sorry for the confusion if any.