Document Object Model
In this chapter you will learn:
What is DOM
HTML document can be represented as a hierarchy of nodes using the DOM.
For the following html code:
<html>/*from j a va 2 s. co m*/
<head>
<title>Sample Page</title>
</head>
<body>
<p id='myP'>Hello World!</p>
</body>
</html>
Its DOM tree is
The root is document node.
The only child of the document node is the <html>
element.
<html>
element is called the document element.
The document element is the outermost element.
p
is an HTML element and body
is also an HTML element.
myP
is an attribute.
HTML elements are represented by element nodes. attributes are represented by attribute nodes. Each node has a type. Nodes have node type, attributes have node type and comments have comment type. The element node and attribute are different in term of type.
In total, there are 12 node types, all of which inherit from a base type.
Next chapter...
What you will learn in the next chapter: