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

Alexander Graham
Alexander Graham
7,966 Points

Is "document.querySelector('body')" and "document.body" the same?

Are these two ways of accessing a selector the same? until now I have used in other courses the "document.querySelector('')", but, can I just write the selector that I want to access straight away like in the video? example "document.body

Thanks

1 Answer

Steven Parker
Steven Parker
231,261 Points

The querySelector function can be used to find any document element. Only the head and body elements have their own shorthand properties on the document object, partly because every document will have one and only one of each of these.