You are here: Reference > JavaScript > client-side > xml handling > properties > nodeTypeString (attribute, Element, ...)

nodeTypeString property (attribute, Element, ...)

Browser support:
Returns the type of the current node as a string.
This property is not supported in HTML documents, only in XML documents.
The nodeType property is similar to the nodeTypeString property, but it returns an integer that represents the type of a node. The nodeType property is supported by the all commonly used browsers in HTML and XML documents also, use it instead.

Syntax:

object.nodeTypeString;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that retrieves the type.
One of the following values:
element
The nodeType is ELEMENT_NODE (1)
attribute
The nodeType is ATTRIBUTE_NODE (2)
text
The nodeType is TEXT_NODE (3)
cdatasection
The nodeType is CDATA_SECTION_NODE (4)
entityreference
The nodeType is ENTITY_REFERENCE_NODE (5)
entity
The nodeType is ENTITY_NODE (6)
processinginstruction
The nodeType is PROCESSING_INSTRUCTION_NODE (7)
comment
The nodeType is COMMENT_NODE (8)
document
The nodeType is DOCUMENT_NODE (9)
documenttype
The nodeType is DOCUMENT_TYPE_NODE (10)
documentfragment
The nodeType is DOCUMENT_FRAGMENT_NODE (11)
notation
The nodeType is NOTATION_NODE (12)
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the nodeTypeString property:
Code
ajax.js
<head>
    <script type="text/javascript" src="ajax.js"></script>
    
    <script type="text/javascript">
        function GetNodeTypes () {
                // create an XML document
            var xmlDoc = CreateXMLDocumentObject ("root");  // defined in ajax.js
            if (!xmlDoc) {
                return null;
            }

            alert ("The type of the document: " + xmlDoc.nodeTypeString);
            alert ("The type of the root node: " + root.nodeTypeString);
        }
    </script>
</head>
<body>
    <button onclick="GetNodeTypes ();">Get different node types!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content