Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) The Browser Environment Recap

DOM or HTML Content?

Does document object refers to HTML content or DOM to select and manipulate elements? Like will 'getElementById' get the element from HTML content or will it look in the DOM to retrieve element.

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

DOM stands for document object model which is a global object to the browser. Above that, you have the window object.

The getElementById is a method that belongs to the document object. It is used to select an element on a page that has the matching id attribute value. It therefore returns the element and not the html content.

@Jamie Reardon so, DOM is same as document object in javascript. correct?

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Yes it is the same thing. You can access properties and methods through JavaScript using the document object. E.g. the write() method writes to the page.