Ask HN: What Is the DOM, Exactly?
DOM is commonly described as a tree of objects (nodes) representing the items in an (XML/HTML) document, although the tree aspect is not mandatory but widespread, and the document object* is presumably representing the DOM. So for the following HTML document:
<html>
<body>
<main>Hello World</main>
</body>
</html>
I expect the document object to kind of look like: html (element): {
\n\t (text),
body (element): {
\n\t (text),
main (element): {Hello World (text)},
\n (text)
},
\n (text)
}
But what I get is more like a mix of nodes, properties, methods and prototypes: URL: ..., <-- a property
activeElement: ..., <-- a property
body: ..., <-- an element
childElementCount: 1, <-- a property
head: ..., <-- an element
main: ..., <-- an element
onclick: ..., <-- a method
<prototype>: ..., <-- a bunch of prototypes
...
Is the DOM actually a tree of objects representing the items in an HTML document PLUS extra data (properties) and the means to manipulate it (methods) or is it just an abstraction (after all it has model in its name) that differs from its implementation (document object)?*what you get when typing document in the browser console or when calling it from Javascript