The Document Object Model (DOM) is a cross-platform and language-independent
application programming interface that treats an HTML, XHTML, or XML document
as a tree structure wherein each node is an object representing a part of the
document. The objects can be manipulated programmatically and any visible
changes occurring, as a result, may then be reflected in the display of the
documentWhen an HTML document is loaded into a web browser, it becomes a document
object. The document object is the root node of the HTML document and the
"owner" of all other nodes:(element nodes, text nodes, attribute
nodes, and comment nodes). The document object provides properties and methods
to access all node objects, from within JavaScript.
NOTE: The document is a part of the Window object and can be accessed as
window.document.
HTML DOM Nodes
In the HTML DOM (Document Object
Model), everything is a node:
- The document itself is a
document node
- All HTML elements are element nodes
- All HTML attributes are attribute nodes
- Text inside HTML elements are text nodes
- Comments are comment nodes
What the Document Object Model is
The Document Object Model is a
programming API for documents. The object model itself closely resembles the
structure of the documents it models. For instance, consider this table, taken
from an
HTML document:
<TABLE>
<ROWS>
<TR>
<TD>Nitin Chauhan</TD>
<TD>Rahul Chauhan</TD>
</TR>
<TR>
<TD>ABC</TD>
<TD>CDE</TD>
</TR>
</ROWS>
</TABLE>
The Document Object Model represents this table like this: