↑
Main Page
Language-Specific DOMs
Property/Method
Type/Return Type Description
nextSibling
Node
Pointer to the next sibling;
null
if this is the last
sibling
hasChildNodes() Boolean
Returns true when
childNodes
contains one or
more nodes
attributes
NamedNodeMap
Contains
Attr
objects representing an element’s
attributes; only used for
Element
nodes
appendChild(
node
) Node
Adds
node
to the end of
childNodes
removeChild(
node
) Node
Removes
node
from
childNodes
replaceChild
Node
Replaces
oldnode
in
childNodes
with
(
newnode
,
oldnode
)
newnode
insertBefore
Node
Inserts
newnode
before
refnode
in
(
newnode
,
refnode
)
childNodes
In addition to nodes, the DOM also defines some helper objects, which are used to work with nodes but
are not necessarily part of a DOM document:
?
NodeList
— an array of nodes indexed numerically; used to represent child nodes of an element
?
NamedNodeMap
— an array of nodes indexed both numerically and name; used to represent ele-
ment attributes
These helper objects provide additional access and traversal methods for dealing with DOM document.
Usage specifics are discussed later.
Language-Specific DOMs
Any XML-based language, such as XHTML and SVG, can make use of the core DOM just introduced
because they are technically XML. However, many languages go on to define their own DOMs that
extend the XML core to provide language-specific features.
Along with developing the XML DOM, the W3C concurrently developed a DOM more specific to
XHTML (and HTML). This DOM defines an
HTMLDocument
and
HTMLElement
as the basis for the imple-
mentation. Each HTML element is represented by its own
HTMLElement
type, such as
HTMLDivElement
representing
<div>
, with the exception of a small subset of elements that don’t require special properties
or methods other than those provided by
HTMLElement
. Throughout the rest of the book, you are intro-
duced to various HTML DOM features as well as to the core XML DOM features.
Regular HTML is not valid XML; however, most modern Web browsers are forgiv-
ing and still parse an HTML document into a proper DOM document (even without
the XML prolog). However, it’s always best to use XHTML code when programming
Web pages to eliminate bad coding habits.
166
Chapter 6
09_579088 ch06.qxd 3/28/05 11:37 AM Page 166
Free JavaScript Editor
Ajax Editor
©
→