4 ms·
The DOM is not HTML and not related to HTML. For the first several years of the web there was no DOM. At that time the web was just HTTP and HTML. A first DO
by throwaway0asd 4y ago
The DOM is not HTML and not related to HTML. For the first several years of the web there was no DOM. At that time the web was just HTTP and HTML. A first DOM version was created by the W3C specifically for HTML. It was created in the proper spirit, but it was technically immature. It is now referred to as DOM level 0. The actual DOM that became the backbone of web technologies was the DOM Level 1 specification released by the W3C in 1998. It and every revision up to DOM Level 3 was released on the same day as a specification update for the XML Schema standard. The current DOM specification that is actively updated and used by the browsers comes from the WHATWG which is based upon DOM Level 4 from the W3C.
The DOM is a tree-based model for conveying information where points on that tree can reference each other in relational terms. The process of finding or describing a point on the DOM from another point on the DOM is called walking the DOM.
Since the DOM is not HTML, XML Schema, or any other specific language you must think of it as a compile target. As an example WASM is not a language, but a compile target for other languages.
Since the DOM is a tree each node on that tree knows: its parent, its children, and its siblings. In this manner the DOM is a living object because those relational properties on each node are always up to date as the DOM modifies. It seems a major point of confusion from your code examples is how the DOM is expressed. You appear to expect the DOM to be expressed as the tree itself. Most DOM trees are extremely large, so most people would find that unhelpful and illegible. The DOM is expressed from the perspective of a single node on that tree.
You also have to understand there are different node types that comprise the DOM, 12 actually. The most common are text, elements, and attributes. You mention document. There is a node type for that.