Close

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!

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

© Hugh Wood 1980-Present