A deep dive into the Document Object Model.
Document Object Model (often abbreviated as DOM) is the tree data structured resulted from parsing HTML. It consists of one or more instances of subclasses of Node and represents the document tree structure. Parsing a simple HTML like this:
<!DOCTYPE html> <html> <body>hi</body> </html>
Will generate the following six distinct DOM nodes:
Note that HTMLHeadElement (i.e.
<head>) is created implicitly by WebKit
per the way HTML parser is specified.
Broadly speaking, DOM node divides into the following categories:
- Container nodes such as Document, Element, and DocumentFragment.
- Leaf nodes such as DocumentType, Text, and Attr.
Document node, as the name suggests a single HTML, SVG, MathML, or other XML document, and is the owner of every node in the document. It is the very first node in any document that gets created and the very last node to be destroyed.