HTML and CSS Reference
In-Depth Information
node is the
<html>
tag, called the
root node
of the document. Below it are the
<head>
and
<body>
tags, which are called
child nodes
of the HTML element. In the
<title>
is the
text
My Title,
which is also a node, called a
text node
. Because it is the last node, the
tree-like structure terminates at that node, also called a
leaf node
. The nodes are divided
into three types of nodes: the
element node
,
attribute node
, and the
text node
. These
types are numbered 1, 2, and 3, for element, attribute, and text node, respectively. In the
example, the
<p> and <h1>
tags are element nodes,
title=“para1”
is an attribute node, and
the text between the
<title>
tags,
My Title
, is an example of a text node. An attribute node
is represented as a property of the HTML element to which it is assigned; for example,
the
<a>
tag has an
href
attribute. In the example,
<a href=“http://www.prenhall.com”>
,
a
is an element node,
href
is an attribute node and the URL is called its
nodeValue
. (The
text nodes are not supported on all browsers.)
Refer to Tables 15.2 and 15.3 for a list of node properties and node methods.
document
root node
<html>
<body>
(last child
)
<head>
(first child)
child nodes
sibling nodes
<title>
<h1>
<p title="para1">
<table>
“My Title”
“heading 1”
“paragraph text”
<tr>
<tr>
<td>
“cell2”
leaf nodes
<td>
“cell1”
<td>
“cell2”
<td>
“cell1”
Figure 15.3
A tree of nodes.
Table 15.2
Node Properties
Property
What It Does
firstChild
Returns the first child node of an element.
lastChild
Returns the last child node of an element.
nextSibling
Returns the next child node of an element at the same level as the current child node.