Predefined constants are available for the possible values of this property, in the scope of the Node object. You can use them directly through the Node interface (Node.ELEMENT_NODE) or through an instance of the Node object. Unfortunately, these constants are not supported by Internet Explorer before version 9, so use the numeric values instead of the predefined constants for a cross-browser solution.
The value can be one of the following values (the value of a predefined constant appears in parentheses after the constant):
ELEMENT_NODE (1)
9
Element node.
ATTRIBUTE_NODE (2)
9
Attribute node.
TEXT_NODE (3)
9
Text node.
CDATA_SECTION_NODE (4)
9
CDATA Section node.
ENTITY_REFERENCE_NODE (5)
9
ENTITY Reference node.
ENTITY_NODE (6)
9
ENTITY node.
PROCESSING_INSTRUCTION_NODE (7)
9
PROCESSING Instruction node.
COMMENT_NODE (8)
9
COMMENT node.
DOCUMENT_NODE (9)
9
DOCUMENT node.
DOCUMENT_TYPE_NODE (10)
9
DOCUMENT Type node.
DOCUMENT_FRAGMENT_NODE (11)
9
DOCUMENT Fragment node.
NOTATION_NODE (12)
9
NOTATION node.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the nodeType property:
<head><scripttype="text/javascript">function GetNodeInfo () {
var div = document.getElementById ("myDiv");
var commentNode = div.firstChild;
var message = "";
message += "The name of the node: " + commentNode.nodeName + "\n";
message += "The type of the node: " + commentNode.nodeType + "\n";
message += "The value of the node: " + commentNode.nodeValue;
alert (message);
}
</script></head><body><divid="myDiv"><!-- this text is not rendered --></div><buttononclick="GetNodeInfo ()">Get node info!</button></body>