readonly unsigned short nodeType
The type of the node—i.e., which subinterface the node implements. The legal values
are defined by the previously listed constants. Since these constants are not supported
by Internet Explorer, however, you may prefer to use hardcoded values instead of the
constants. In HTML documents, the common values for this property are 1 for Element
nodes, 3 for Text nodes, 8 for Comment nodes, and 9 for the single top-level Document
The value of a node. For Text nodes, it holds the text content.
readonly Document ownerDocument
The Document object with which this node is associated. For Document nodes, this
. Note that nodes have owners even if they have not been inserted into a
readonly Node parentNode
The parent (or container) node of this node, or
if there is no parent. Note that the
Document and DocumentFragment nodes never have parent nodes. Also, nodes that
have been removed from the document, or that are newly created and have not yet been
inserted into the document tree, have a
readonly Node previousSibling
The sibling node that immediately precedes this one in the
array of the
if there is no such node.
nodes, this property is just a synonym for the
nodes, querying this property returns the concatenated
text content of all Text node descendants. Setting this property on a Element or Docu-
mentFragment replaces all descendants of that element or fragment with a single new
Text node that holds the specified value.
Node appendChild(Node newChild)
This method adds the node
to the document, inserting it as the last child of this
is already in the document tree, it is removed from the tree and then rein-
serted at its new location. If
is a DocumentFragment node, it is not inserted itself;
instead, all its children are appended, in order, to the end of this node’s
Note that a node from (or created by) one document cannot be inserted into a different docu-
ment. That is, the
must be the same as the
property of this node. (See
). This method returns the Node that
was passed to it.
Node cloneNode(boolean deep)
method makes and returns a copy of the node on which it is called. If passed
, it recursively clones all descendants of the node as well. Otherwise, it
clones only the node and none of its children. The returned node is not part of the document
tree, and its
. When an Element node is cloned, all of its attributes
are also cloned. Note, however, that event-listener functions registered on a node are not
unsigned short compareDocumentPosition(Node other)
This method compares the document position of this node to the document position of the
node and returns a number whose set bits describe the relationship between the nodes.
If the two nodes are the same, no bits are set and this method returns 0. Otherwise, one or
more bits will be set in the return value. The
constants listed above give
symbolic names for each of the bits, which have the following meanings:
The two nodes are not in the same document, so their position cannot be compared.
node appears before this node.
node comes after this node.
node contains this node. When this bit is set, the PRECEDING bit is always
node is contained by this node. When this bit is set, the FOLLOWING bit is
always also set.
if this node has one or more children or
if it has none.
Node insertBefore(Node newChild, Node refChild)
This method inserts the node
into the document tree as a child of this node and then
returns the inserted node. The new node is positioned within this node’s
so that it comes immediately before the
at the end of
, just as with the
method. Note that it is illegal to
call this method with a
that is not a child of this node.
is already in the document tree, it is removed from the tree and then reinserted at
its new position. If
is a DocumentFragment node, it is not inserted itself; instead,
each of its children is inserted, in order, at the specified location.
boolean isDefaultNamespace(string namespace)
if the specified
URL is the same as the default namespace URL returned
boolean isEqualNode(Node other)
if this node and
are identical, with equal type, tagname, attributes, and
(recursively) children. Returns
if the two nodes are not equal.
boolean isSameNode(Node other)
if this node and
are the same node and
otherwise. You can also
simply use the
string lookupNamespaceURI(string prefix)
This method returns the namespace URL associated with the specified namespace
if there isn’t one. If
, it returns the URL of the default namespace.
string lookupPrefix(string namespace)
This method returns the namespace prefix associated with the specified
if there is none.
This method normalizes the text node descendants of this node, merging adjacent nodes and
removing empty nodes. Documents do not normally have empty or adjacent text nodes, but
this can occur when a script adds or removes nodes.
Node removeChild(Node oldChild)
This method removes
array of this node. It is an error to call
this method with a node that is not a child.
continues to be a valid node and can be reinserted into the document
Node replaceChild(Node newChild, Node oldChild)
This method replaces
must be a child
of this node. If
is already part of the document, it is first removed from the document
before being reinserted at its new position. If
is a DocumentFragment, it is not in-
serted itself; instead, each of its children is inserted, in order, at the position formerly occupied
a read-only array-like object of Nodes
A NodeList is a read-only array-like object whose elements are
objects (usually Elements).
property specifies how many nodes are in the list, and you can retrieve those nodes
from indexes 0 through
-1. You can also pass the desired index to the
instead of indexing the NodeList directly. The elements of a NodeList are always valid Node
objects: NodeLists never contain
NodeLists are commonly used: the
property of Node, and the return values
are all NodeLists, for example. Because NodeList is an array-like
object, however, we often refer to those values informally as arrays, using language like “the
Note that NodeList objects are usually live: they are not static snapshots but immediately
reflect changes to the document tree. For example, if you have a NodeList that represents the
children of a specific node and you then delete one of those children, the child is removed
from your NodeList. Be careful when you are looping through the elements of a NodeList:
the body of your loop can make changes to the document tree (such as deleting nodes) that
can affect the contents of the NodeList!
readonly unsigned long length
The number of nodes in the NodeList.
Node item(unsigned long index)
Returns the Node at the specified index or
if the index is out of bounds.
an <option> in a Select element
The Option object describes a single option displayed within a
object. The properties
of this object specify whether it is selected by default, whether it is currently selected, the
position it has in the
array of its containing Select object, the text it displays, and
the value it passes to the server if it is selected when the containing form is submitted.
For historical reasons, the Option element defines a constructor that you can use to create
and initialize new Option elements. (You can also use the normal
method, of course.) Once a new Option object is created, it can be appended
collection of a Select object. See
new Option([string text, string value, boolean defaultSelected, boolean selected])
constructor creates an
element. The four optional argument specify
) of the element and the initial values of the
This property mirrors the HTML
attribute. It defines the initial selectedness of
the option, and also the value that is used when the form is reset.
if this option is disabled. Options are disabled if they or a containing
readonly Form form
element, if any, of which this Option element is a part.
readonly long index
The index of this Option element within its containing Select element. (See also
The value of the HTML
attribute if there is one, or otherwise the
) of this Option.
if this option is currently selected, or
) of this Option element, with leading and trailing whitespace
removed and runs of two or more spaces replaced with a single space character.
The value of the HTML
attribute, if this Option has one, or the
an HTML form <output> element
Node, Element, FormControl
The Output object represents an HTML form
element. In browsers that support
them, Output objects implement most of the properties of
This property is the initial value of the Output element’s
the form is reset, its
is restored to this value. If this property is set and the Output
element is currently displaying its previous
, the new default value will be
displayed. Otherwise, the currently displayed value will not be changed.
readonly DOMSettableTokenList htmlFor
attribute of an
element is a space-separated list of the IDs of
elements whose values contributed to the computed content displayed by the
instead. You can get and set this property as if it was an ordinary string
value, or you can use the methods of
to query and set individual element
IDs from the list.
event object for pageshow and pagehide events
Browsers fire a pageshow event after the load event when a document first loads, and then
fire another pageshow event each time the page is restored from the in-memory history cache.
A PageTransitionEvent object is associated with each pageshow event, and its
if the page is being restored rather than loaded or reloaded.
Pagehide events also have an associated PageTransitionEvent object, but the
erty is always
for pagehide events.
Pageshow and pagehide events are triggered on the Window object. They do not bubble and
have no default action to cancel.
readonly boolean persisted
For pageshow events, this property is
if the page was loaded (or reloaded) from the
network or the disk cache. It is
if the page being shown was restored from the in-
memory cache without being reloaded.
For pagehide events, this property is always
history transition event
Web applications that manage their own history (see §22.2) use the
to create a new entry in the browsing history and associate a state value or object with
it. When the user uses the browser’s Back or Forward buttons to navigate between those saved
states, the browser triggers a popstate event on the Window object and passes a copy of the
saved application state in the associated PopStateEvent object.
readonly any state
This property holds a copy of the state value or object that was passed to the
can be any value that
can be cloned with the structured clone algorithm (see “Structured Clones”
on page 672).
a processing instruction in an XML document
This infrequently used interface represents a processing instruction (or PI) in an XML docu-
ment. Programmers working with HTML documents will never encounter a Process-
The content of the processing instruction (i.e., the first nonspace character after the tar-
get, up to but not including the closing
readonly string target
The target of the processing instruction. This is the first identifier that follows the opening
; it specifies the “processor” for which the processing instruction is intended.
a progress bar
A Progress object represents an HTML
element and displays a graphical repre-
sentation of progress toward the completion of some kind of task.
Documents you may be interested
Documents you may be interested