-
Notifications
You must be signed in to change notification settings - Fork 2
DOM
Elyas Rahimi edited this page Jan 21, 2026
·
1 revision
The DOM (Document Object Model) module provides an in-memory representation of a web document's structure. It implements a tree data structure that mirrors the hierarchical organization of HTML elements.
- Store the structural representation of HTML documents
- Maintain element properties, attributes, and content
- Support tree navigation and manipulation
- Provide the foundation for styling and layout operations
The DOM is organized as a tree where:
- Each node represents an HTML element, text content, comment, or the document itself
- Parent-child relationships define the document structure
- Siblings are stored in order to preserve document sequence
| Type | Purpose | Example |
|---|---|---|
| Element | HTML elements |
<div>, <p>, <a>
|
| Text | Text content | "Hello World" |
| Comment | HTML comments | <!-- comment --> |
| Document | Root of tree | Implicit container |
Represents a single element in the DOM tree:
- Element data: Tag name, attributes, classes, ID
- Parent reference: Link to parent node
- Children list: Ordered list of child nodes
- Text content: Inner text for text nodes
Elements store attributes as key-value pairs:
-
id: Unique identifier -
class: CSS class names -
href: Link target (for anchors) - Custom attributes: Any data attributes
- Get parent node
- Get child nodes
- Get sibling nodes
- Find nodes by selector or criteria
- Add child nodes
- Remove nodes
- Update attributes
- Modify text content
- Find elements by tag name
- Find elements by class
- Find elements by ID
- Get descendants matching criteria
Uses DOM structure to apply CSS styles and calculate computed properties
Traverses DOM tree to calculate positioning and dimensions
Iterates through DOM to render visible content
Provides DOM APIs (getElementById, querySelector, etc.) for script access
- Efficient node representation to minimize memory usage
- Shared ownership through reference counting when needed
- Lazy evaluation of properties where possible
- Follows W3C DOM specification
- Supports standard DOM methods and properties
- Compatible with CSS selectors for element matching
Document
├── Element: html
│ ├── Element: head
│ │ └── Element: title
│ │ └── Text: "My Page"
│ └── Element: body
│ ├── Element: h1
│ │ └── Text: "Welcome"
│ └── Element: p
│ └── Text: "Hello, world!"
- Virtual DOM for efficient updates
- DOM event system
- MutationObserver support
- Performance optimizations for large documents