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 The Browser Environment Introduction to Browser Events

RhysRhys Dyson
RhysRhys Dyson
435 Points

DOM Hierarchy - Top Levels

So I understand that the DOM hierarchy works exactly like the HTML/CSS Box model for selecting elements with JavaScript.

At the top of the tree, is the document. Is the document the entire project, or just the index.html file (or the current active page).

Are we able to select and specify documents by HTML page using the document selector. Is that the importance of understanding the DOM model and structure, to specify code for different pages and sections or our projects?

Example:

  • Create a conditional to only run on a specific page/document (although in most cases, for the web, you would just include the script in that specific page's head/footer). But maybe not so much for an app?

1 Answer

Steven Parker
Steven Parker
218,692 Points

The DOM describes the organization of each individual page of HTML code. So the "document" would be the current active page.