Node Properties nodeName Type : String
Description : This string property represents the name of the node. Depending on the type
of node that this property is used on, the results will vary.
Comments : Table 5.1 shows that the only node types that have nontrivial usage of
nodeName are Element and Attribute. It is not recommended to use nodeName to find
out what kind of node you have a hold of. The property nodeType provides that
functionality and is described later in this section. If nodeName is called on an element
with a namespace, such as , then nodeName will be foo:root, whereas
the baseName (described later) will be root.
Example :
The first alert produces
someElement, and the second alert produces someAttribute. The
documentElement property is described in the
Document section
later in this chapter.
Briefly, this property points to the topmost element, in this case the someElement
element. The nodeName property is then called on this topmost element, returning the
string someElement to the alert method, which in turn displays the tag name in a dialog
box.
Table 5.1: nodeName Behavior for Different Node Types Node type nodename property Document
#document
Element
tag name
Attribute
attribute name
Text
#text
CDATASection
#cdata-section
Comment
#comment
- 118 -
Entity
entity name
Notation
notation name
EntityReference
name of entity referenced
ProcessingInstruction
target (the first word following the
<
? )
DocumentType
document type name (also the name of the topmost
element)
#document-fragment