The W3C Document Object Model (DOM) Is A Platform and Language-Neutral Interface That Allows Programs and Scripts To Dynamically Access and Update The Content, Structure, and Style of A Document."
The W3C Document Object Model (DOM) Is A Platform and Language-Neutral Interface That Allows Programs and Scripts To Dynamically Access and Update The Content, Structure, and Style of A Document."
The DOM defines a standard for accessing HTML and XML documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that
allows programs and scripts to dynamically access and update the content, structure, and style
of a document."
The XML DOM defines the objects and properties of all XML elements, and the methods to
access them.
The HTML DOM defines the objects and properties of all HTML elements, and the methods to
access them.
In other words:
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
DOM Nodes
According to the W3C HTML DOM standard, everything in an HTML document is a node:
The HTML DOM views HTML documents as tree structures. The structure is called a Node
Tree:
With the HTML DOM, all nodes in the tree can be accessed by JavaScript. All HTML elements
(nodes) can be modified, and nodes can be created or deleted.
The nodes in the node tree have a hierarchical relationship to each other.
The terms parent, child, and sibling are used to describe the relationships. Parent nodes have
children. Children on the same level are called siblings
The following image illustrates a part of the node tree and the relationship between the nodes:
Look at the following HTML fragment:
<html>
<head>
<title>DOM Tutorial</title>
</head>
<body>
<h1>DOM Lesson one</h1>
<p>Hello world!</p>
</body>
</html>
and:
The <html> node has two child nodes: <head> and <body>
The <head> node has one child node: the <title> node
The <title> node also has one child node: the text node "DOM Tutorial"
The <h1> and <p> nodes are siblings and child nodes of <body>
and:
The HTML DOM can be accessed with JavaScript (and other programming languages).
All HTML elements are defined as objects, and the programming interface is the object
methods and object properties .
A property is a value that you can get or set (like the name or content of a node).
The getElementById() method returns the element with the specified ID:
Example
<html>
<body>
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
<script>
x=document.getElementById("intro");
document.write("<p>The text from the intro paragraph: " + x.innerHTML + "</p>");
</script>
</body>
</html>
HTML DOM Objects - Methods and Properties
A person is an object.
All persons have these methods, but they are performed at different times.
A person's properties include name, height, weight, age, eye color, etc.
All persons have these properties, but their values differ from person to person.
Method Description
getElementById() Returns the element that has an ID
attribute with the a value
getElementsByTagName() Returns a node list (collection/array of
nodes) containing all elements with a
specified tag name
getElementsByClassName() Returns a node list containing all
elements with a specified class