Represents the attributes of an Element object.
Attributes for an element node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes.html
- Remarks
-
This property returns a listing of all the attributes bound to this Node . Since only
Element nodes support attributes, most Node types will return a null
value for this property.
NamedNodeMap s are essentially the DOM-equivilant of a hash. This property provides an alternative
to the specific Element.getAttribute and Element.hasAttribute methods, which are
usually used when you already know which attributes an element has. For those circumstances when you want to do
some automatic discovery of attributes and their values, this property provides a convenient way to iterate through
the element's attributes.
This property also has the added benefit of being usable across all nodes, not just Element nodes.
Therefore no checking needs to be done ahead of time to verify if a node is an Element ; rather you
can iterate over the attributes list, since any element that has no attributes, or any other DOM node,
will have a null value for this property.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Child nodes of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/children.html
- Remarks
-
The list of nodes that are immediate children of this node. The DOM is a heirarchial structure of Node
objects. This property, combined with the parentNode properties provide the basics for defining
this structure. Several convenience properties are provided for accessing some frequently-used children nodes, namely the
firstChild and lastChild properties.
Since the NodeList class can be referenced as an array as well as its object-oriented interface,
one can easily iterate through the contents of a node using standard JavaScript for loops. Because
this property is read-only, you cannot alter the NodeList to effect this node's contents. Instead,
the methods for addeding and removing nodes should be used, which will result in this being updated automatically.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
First child node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the first child node from the list of the current node's children. If this node doesn't have any
children, a null value will be returned.
This is functionally equivilant to invoking node.childNodes.NodeList.item(0) ,
though this
method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Last child node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the last child node from the list of the current node's children. If this node doesn't have any
children, a null value will be returned.
This is functionally equivilant to invoking node.childNodes.NodeList.item(node.childNodes.NodeList.length
- 1) , though this
method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Local part of an element or attribute name if it the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
URI of the namespace for an element or attribute node if the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
Sibling node immediately after the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the next node to the current one within the parent node's children. If this node is the last child
within it's parent, then a null value will be returned.
When working with a node, it is often useful to be able to manipulate or search the nodes surrounding it. For instance, if
given
a node representing a label, you might want to find the text node immediately next to it. To help with this, the
nextSibling property allows you to traverse to neighboring nodes in the DOM.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Name of the node. Same as tag name for element nodes.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This returns a name that represents this node's name. Depending on the type of object this is, this property will either
return the name identifying this object; for instance, if this node is a Element or Attr object,
then the tag or attribute name is returned. In other cases some place-holder text will be returned.
nodeName node-type valuesTypeleftValueleftAttr
Attribute name
|
CDATASection #cdata-section |
Comment #comment |
Document #document |
DocumentFragment #document-fragment |
DocumentType
Document type name
|
Element
Tag name
|
Entity
Entity name
|
EntityReference
Name of entity referenced
|
Notation
Notation name
|
ProcessingInstruction
Target
|
Text #text |
If XML Namespaces were defined for this node and this node is a Element or
Attr object (since these are the only node types that support the use of namespaces),
this property returns the node name including the prefix and localName.
Returns an upper case tag name.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Type of node. See Remarks for valid values.
|
Show Details |
5.5+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- IE: IE 5.0 on Windows does not assign nodeType attributes. Fixed in IE 5.5.
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This property returns an integer indicating what type of DOM Node this object represents.
Because the Node class is inherited by several other, more specific DOM objects, this property
is a programmatic way of determining what an arbitrary node is, and therefore can tell the programmer how to interact
with it. There are a series of constants defined in this object that can be used to refer to this property:
nodeList constant valuesValuerightConstantleft1 ELEMENT_NODE|
2 ATTRIBUTE_NODE|
3 TEXT_NODE|
4 CDATA_SECTION_NODE|
5 ENTITY_REFERENCE_NODE|
6 ENTITY_NODE|
7 PROCESSING_INSTRUCTION_NODE|
8 COMMENT_NODE|
9 DOCUMENT_NODE|
10 DOCUMENT_TYPE_NODE|
11 DOCUMENT_FRAGMENT_NODE|
12 NOTATION_NODE|
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Value of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This represents the value of the node. Only Attr , CDATASection , Comment ,
ProcessingInstruction , and Text objects can contain a value in this property. For all
other types of objects this property will return null, and setting it to a different value has no effect.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Document object that contains this node.
|
Show Details |
6.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/document.html
- Remarks
-
Refers to the Document object that this node exists in. Because a node must be created as a child of a
Document , and since Node objects cannot be moved arbitrarily from one document to another
(not without duplicating it), this is a way of referring to the parent document for a node so that document-wide method calls
can be used for a node.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Parent node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
This property contains a reference to the parent node for the current node. Since the DOM is a heirarchial structure of
nodes, the parentNode and childNodes properties tie the collection of nodes
together.
Not all nodes can have parents however. Attr , Document , DocumentFragment ,
Entity and Notation objects and as such will contain a null value for this property.
As well this property will be null for newly-created nodes that have yet to be added to a location within the DOM tree.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Namespace prefix for an element or attribute node if the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
Sibling node immediately before the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the previous node to the current one within the parent node's children. If this node is the first child
within it's parent, then a null value will be returned.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Name of the attribute object.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes.html
- Remarks
- Due to the nature of DOM Element attributes, the
name value must be unique across attributes attached to the
same element node.
- Availability
-
W3C|HTML DOM Level 2
|
Parent node that the attribute is attached to.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Remarks
- Because attributes are meaningless unless they are bound to an
Element , this property allows you to find the
node that an attribute is attached to. If this attribute is not yet attached to a node, the value of this property is set
to null .
- Availability
-
W3C|HTML DOM Level 2
|
If true, specifies that the attribute was explicitly created.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes.html
- Remarks
-
If true, indicates that this attribute value was explicitly set from a source XML document or via a DOM method call. Otherwise,
the specified property is false.
For example, if a document has an element definition with a "width" attribute with a default value of "3", the specified
property for the Attr of the element is set to false when the document loads. If the value of the is subsequently
changed, this property will change to true . You can only revert the specified property back to its
original value by deleting the attribute from its parent node so that the DTD recreates the default attribute.
- Availability
-
W3C|HTML DOM Level 2
|
Value of the attribute.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes.html
- Remarks
Returns and sets the value of the attribute as a String. Replaces entity references with their values. In addition to methods
for retrieving Attr objects, the Element object has methods for accessing the value of an attribute
without having to deal directly with the Attr object.
- Availability
-
W3C|HTML DOM Level 2
|
Returns true if the node is an element node with attributes.
|
Show Details |
no |
1.0+ |
6.0+ |
7.0+ |
1.3+ |
Returns
-
Using hasAttributesvar obj = document.Document.getElementById('EmailAddress');
if (obj.hasAttributes()) {
window.alert("The node " + obj.Node.nodeName + " has attributes");
}
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes3.html
- Remarks
- Returns true if this node is an
Element and has any attributes. Returns false if there are none. Equivilant to
checking node.attributes .NamedNodeMap.length > 0 .
- See Also
-
Element.getAttribute|Element.hasAttribute|Node.attributes
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Returns true if the node has child nodes.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Returns
-
Using hasChildNodesvar obj = document.Document.getElementById('EmailAddress');
if (obj.hasChildNodes()) {
window.alert("The node " + obj.Node.nodeName + " has children");
}
- Remarks
- Returns true if this node has any child nodes. Returns false if there are none. Equivilant to checking
node.childNodes .NodeList.length
> 0 .
- See Also
-
Node.childNodes
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
isSupported( String feature, [ String version]) : Boolean
Returns true if the specified feature and version are supported.
|
Show Details |
no |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
String |
feature |
Name of the feature. |
String |
version |
(optional)Version of the feature.
|
Returns
- Remarks
- Tests whether a node supports the specified feature. Similar to the
DOMImplementation.hasFeature method and
takes the same feature names. If version is null, returns true if any version of the feature is supported.
- See Also
-
DOMImplementation.hasFeature
- Availability
-
HTML DOM Level 2|W3C
|
Merges text nodes adjacent to the element to create a normalized DOM.
|
Show Details |
N/A |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/splittext.html
- Remarks
-
Normalizes any
Text nodes contained under this node and all of its children.
Merges any adjacent Text nodes into one object, so that the nodes reflect how they would be structured if this
XML document were freshly loaded.
Normalize() is useful for manipulating the text content of nodes for editing. Instead
of worrying about altering existing Text nodes, you can simply add new nodes and perform the normalize
when you finish your updates.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Attributes are properties of Elements and do not have their own identities. Although an Attr
is a descendant
of a Node
, an Attr
is not placed in a parentNode
, nextSibling
or previousSibling
,
and its own instances of those properties are null
. Additionally, an Attr
objects may only be a
child of an Element
object.
Set the value of an attribute either via the DOM, from a source document, or from a DTD or other XML Schema
.
If a declaration for an attribute exists that defines a default value, and the attribute in question does not exist, the attribute
will be automatically added with the given value. Usually, however, an attribute does not exist until it is explicitly added.