Node.nodeType – Don’t use for backwards compatability!

Just a note the following, Node.nodeType isn’t in IE8 or below so if you are targeting those browsers make sure to use the number instead of the textual format.

The node type values:
Node.ELEMENT_NODE == 1
Node.ATTRIBUTE_NODE == 2
Node.TEXT_NODE == 3
Node.CDATA_SECTION_NODE == 4
Node.ENTITY_REFERENCE_NODE == 5
Node.ENTITY_NODE == 6
Node.PROCESSING_INSTRUCTION_NODE == 7
Node.COMMENT_NODE == 8
Node.DOCUMENT_NODE == 9
Node.DOCUMENT_TYPE_NODE == 10
Node.DOCUMENT_FRAGMENT_NODE == 11
Node.NOTATION_NODE == 12

example:
this.nodeType == 3
not
this.nodeType == Node.TEXT_NODE
Will check the node type you have loaded to see if it is one that holds text.

example 2:
this.nodeType == 11
not
this.nodeType == DOCUMENT_FRAGMENT_NODE
This will check to see if the node holds other nodes, ie is a DOM fragment.

Good hunting dom manipulators!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s