DOM Tree
DOM Tree
Section titled “DOM Tree”Introduction
Section titled “Introduction”The DOM represents an HTML document as a tree of nodes, where each node corresponds to an element, text, attribute, or comment.
Visual Explanation
Section titled “Visual Explanation”flowchart TD A["document"] B["<html>"] C["<head>"] D["<body>"] E["<title>"] F["<h1>"] G["<p>"]
A --> B B --> C B --> D C --> E D --> F D --> GThe Document Object
Section titled “The Document Object”// The DOM starts with the document objectconsole.log(document); // The entire HTML documentconsole.log(document.head); // <head> elementconsole.log(document.body); // <body> elementconsole.log(document.title); // Page titleNode Types
Section titled “Node Types”| Node Type | Example |
|---|---|
| Element node | <div>, <p>, <h1> |
| Text node | ”Hello World” inside an element |
| Comment node | <!-- comment --> |
| Document node | The document object itself |
Summary
Section titled “Summary”- DOM is a tree of nodes representing the HTML document
documentis the root entry point- Node types: element, text, comment, document
- Each element node can have child nodes