DHTML Object Properties DHTML Objects
DOM Level 1 Specification.
Retrieves the type of the requested node.
HTML |
N/A |
Script |
iType = oNode.nodeType |
iType |
Specifies an integer indicating the nodeType of the requested node. |
The DOM defines the following constants:
- The node is an Element.
- The node is an Attr.
- The node is a Text node.
- The node is a CDATASection.
- The node is an EntityReference.
- The node is an Entity.
- The node is a ProcessingInstruction.
- The node is a Comment.
- The node is a Document.
- The node is a DocumentType.
- The node is a DocumentFragment.
- The node is a Notation.
The property is read-only with no default value.
The nodeType property returns an integer between 1 and 12 that specifies the DOM node type as enumerated in the table above. Each node type determines the valid values possible for the node, and whether the node can have child nodes.
The following examples demonstrate implementation of the nodeType attribute.
The sample below retrieves the nodeType value of a particular element, in this case the firstChild of the documentElement property of this document.
var nType = document.documentElement.firstChild.nodeType;
alert ( nType );
Show me
The sample below shows how to retrieve the nodeType values of all the nodes in the BODY of this document. A NodeList object is created, and a loop iterates thru all the objects in the NodeList, gets each object’s nodeType that is then used to access an array's index whose value corresponds to the name of the node type.
function nodeTypeDemo ( ) {
var all, list, types;
all = document.body.childNodes;
list "nodeTypes of all childNodes of the BODY\n';
types = new Array ( '', 'Element', 'Attr',
'Text node', 'CDATASection', 'EntityReference',
'Entity', 'ProcessingInstruction', 'Comment',
'Document', 'DocumentType', 'DocumentFragment',
'Notation' );
for ( n = 0; n < all.length; n++ ) {
list += "\n" + types [ all [ n ] .nodeType ] + ' ';
list += n + ' ' + all [ n ] .nodeName;
}
return ( list );
}
Press your browser back button after.
Show me
nodeName, nodeValue