JavaScript JavaScript and the DOM The Browser Environment Recap

Rushabha Jain
Rushabha Jain
Full Stack JavaScript Techdegree Student 11,140 Points

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
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.