The following content will provide a detailed introduction to the inheritance relationships between the three interfaces `Node`, `Element`, and `HTMLElement` in the DOM, as well as their respective main subtypes.
Through this document, you will clearly understand:
Node as the foundation of all DOM nodes, including what node types it contains (such as document, element, text, comment, etc.).
The role of Element on top of Node, and how it divides into different branches like HTML, SVG, MathML, etc.
HTMLElement as the base class for all HTML elements, and what common specific interfaces it has underneath (such as <div>, <input>, <canvas>, etc.).
Finally, provide a complete inheritance tree to help you intuitively grasp the full picture from the top-level generic nodes to the bottom-level specific tag interfaces.
Definition Node is the most fundamental interface in the entire DOM (Document Object Model) tree, located at the top of the inheritance chain. Any "node" in the document tree (including elements, text, comments, the document itself, etc.) inherits from Node.
Main Characteristics
Has universal properties and methods, such as .parentNode, .childNodes, .appendChild(), .removeChild(), etc.
Can represent document nodes (Document), element nodes (Element), text nodes (Text), comment nodes (Comment), document fragments (DocumentFragment), and other types.
Hierarchically positioned at:
EventTarget → Node
In other words, Node itself inherits from EventTarget, thus having event listening and dispatching capabilities.
Definition Element is also an interface that inherits from Node, representing "element nodes". Compared to Node, Element additionally provides element-related properties and methods, such as .tagName, .getAttribute() / .setAttribute(), .classList, .querySelector(), etc.
Main Characteristics
As long as it's a tag node in HTML or XML (e.g., <div>, <span>, <svg>, <circle>, <math>, custom elements, etc.), it's classified as Element or its subtypes in the DOM.
In the inheritance chain:
EventTarget → Node → Element
Element itself is further subdivided into:
├── HTMLElement (Base class for all HTML tags)├── SVGElement (Base class for all SVG elements)├── MathMLElement (Base class for all MathML elements)└── (And possibly other XML/custom element types in the future...)
Each type has its own additional methods and properties. For example, SVGElement provides SVG-specific methods like getBBox(), getCTM(), while HTMLElement provides HTML-specific properties and methods like .innerText, .style, .dataset, .click(), etc.
Definition HTMLElement is the common parent class for all standard HTML elements (<div>, <span>, <input>, <form>, etc.) corresponding interfaces. In browsers, when you write <div>...</div>, what you eventually get in JS is an instance that inherits from HTMLElement — specifically of type HTMLDivElement.
Main Characteristics
Provides properties and methods common to HTML elements, such as:
Global attributes: .id, .className, .title, .dataset
Form related: For form elements, there are also .disabled, .value, .checked, etc.
In the inheritance chain:
EventTarget → Node → Element → HTMLElement
All specific HTML element types (such as <a>, <button>, <canvas>, etc.) inherit from HTMLElement and each extends additional properties and methods (e.g., HTMLCanvasElement has .getContext(), HTMLAnchorElement has .href, .target, etc.).
Below is a tree diagram showing the inheritance system from Node downward, listing common subtypes. For clarity, the entire tree is written in several levels.
Node is the most universal node interface in the DOM, representing various "nodes" — from the document itself to elements, text, comments, attributes, etc.
Element inherits from Node, representing "element nodes", including HTML, SVG, MathML, XML, custom tags, etc.
HTMLElement inherits from Element, specifically corresponding to HTML tags, and is the base class for all HTML element interfaces (such as HTMLDivElement, HTMLInputElement, etc.).
Through the above tree structure, you can intuitively see:
EventTarget → Node → Element → (subdivided into SVGElement, MathMLElement, HTMLElement…) ↓ HTMLAnchorElement, HTMLDivElement, …
As well as the parallel existence of SVGElement (with dozens of SVG interfaces underneath), MathMLElement (MathML interfaces), etc. under Element.