nodeType (W3C DOM Core property)

Spec
Version Depr. Static Read-only
DOM1 No No Yes
Browser support (more…)
IE6+ FF1.5+ SA3+ OP9+
Full Full Full Full

Example

var type = node.nodeType;

In the example above, the type variable will be a number that represents node's type, as listed above.

So if we take this HTML example:

<abbr title="Laughing My Ass Off">LMAO</abbr>

The abbr element would have the nodeType 1, its title attribute would have the nodeType 2, and the text node inside it would have the nodeType 3.

Description

A numeric code that represents the type of this node:

Table 1. nodeType integers listed by DOM interface
Interface nodeType
Element 1
Attr 2
Text 3
CDATASection 4
EntityReference 5
Entity 6
ProcessingInstruction 7
Comment 8
Document 9
DocumentType 10
DocumentFragment 11
Notation 12

This property is readonly.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Full Full Full Full Full Partial Partial Full Full Full

In Internet Explorer 5.5 in HTML it's only possible to refer to an attribute's value, not to the node itself; there is no way to retrieve the nodeType property of an attribute. This browser also identifies Comment nodes as Element nodes (they return the nodeType 1); and it cannot retrieve the nodeType of a Document (it has an object reference, but its nodeType is undefined).

Safari 1.3 and 2 in HTML mode1 cannot retrieve the nodeType of a Comment node, because they cannot see comments at all.

Footnotes

1 On XHTML or HTML pages served as text/html.

User-contributed notes

There are no comments yet.

Related Products