Document Object Model: Difference between revisions

Content deleted Content added
DOM tree structure: MOS:HEADCAPS
Line 78:
A Document Object Model (DOM) tree is a hierarchical representation of an HTML or [[XML]] document. It consists of a root node, which is the document itself, and a series of child nodes that represent the elements, attributes, and text content of the document. Each node in the tree has a parent node, except for the root node, and can have multiple child nodes.
 
=== Elements as Nodesnodes ===
Elements in an HTML or XML document are represented as nodes in the DOM tree. Each element node has a tag name, attributes, and can contain other element nodes or text nodes as children. For example, an HTML document with the following structure:<syntaxhighlight lang="html">
<html>
Line 103:
</syntaxhighlight>
 
=== Text Nodesnodes ===
Text content within an element is represented as a text node in the DOM tree. Text nodes do not have attributes or child nodes, and are always leaf nodes in the tree. For example, the text content "My Website" in the title element and "Welcome" in the h1 element in the above example are both represented as text nodes.