Let’s get a more in-depth look at DOM nodes.
In this chapter we’ll see more into what they are and learn their most used properties.
DOM node classes
Different DOM nodes may have different properties. For instance, an element node corresponding to tag <a> has link-related properties, and the one corresponding to <input> has input-related properties and so on. Text nodes are not the same as element nodes. But there are also common properties and methods between all of them, because all classes of DOM nodes form a single hierarchy.
Each DOM node belongs to the corresponding built-in class.
The root of the hierarchy is EventTarget, that is inherited by Node, and other DOM nodes inherit from it.
Here’s the picture, explanations to follow:
The classes are:
-
EventTarget – is the root “abstract” class for everything.
Objects of that class are never created. It serves as a base, so that all DOM nodes support so-called “events”, we’ll study them later.
-
Node – is also an “abstract” class, serving as a base for DOM nodes.
It provides the core tree functionality:
parentNode,nextSibling,childNodesand so on (they are getters). Objects ofNodeclass are never created. But there are other classes that inherit from it (and so inherit theNodefunctionality). -
Document, for historical reasons often inherited by
HTMLDocument(though the latest spec doesn’t dictate it) – is a document as a whole.The
documentglobal object belongs exactly to this class. It serves as an entry point to the DOM. -
CharacterData – an “abstract” class, inherited by:
-
Element – is the base class for DOM elements.
It provides element-level navigation like