DEV Community

Cover image for Understanding the HTML DOM: Document Objects Model
Troels Agergaard
Troels Agergaard

Posted on

Understanding the HTML DOM: Document Objects Model

The Document Object Model (DOM) is a fundamental part of how web browsers interpret and manipulate HTML documents. By breaking the DOM into three main components, we can understand it as follows:

The Document is the HTML file that the browser loads. This document serves as the foundation from which all elements are identified and organized.

Here is an example of a simple HTML document:
The entire HTML structure makes up the document. The entire HTML structure makes up the document.

The Objects or HTML element in the document is represented as an object in the DOM. The browser converts HTML tags into a hierarchical structure of objects, which can be manipulated using JavaScript.

For example:
<h1> is an object.
<p> is an object.
<body> is an object that contains other objects.

We can access and modify these objects using JavaScript:
What is the DOM, document object model in HTMLThis code changes the content of the <h1> element.

The Model (Structure and Hierarchy) organizes objects into a tree structure, where some elements are parents, and others are children and together, they form the model.

Example of the DOM structure for the previous HTML document:
Image descriptionIn this model, <html> is the root, <head> and <body> are child nodes, and each element within them follows the hierarchy.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay