Entry
How do I access constants of a DOM interface with JavaScript?
How do I access the different node types?
Apr 27th, 2000 02:02
Rey Nuņez, Martin Honnen,
W3C DOM LEVEL 1 (and 2 too) specifies some constants for interfaces for
example, the "Node" interface defines the following constants:
const unsigned short ELEMENT_NODE = 1;
const unsigned short ATTRIBUTE_NODE = 2;
const unsigned short TEXT_NODE = 3;
const unsigned short CDATA_SECTION_NODE = 4;
const unsigned short ENTITY_REFERENCE_NODE = 5;
const unsigned short ENTITY_NODE = 6;
const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
const unsigned short COMMENT_NODE = 8;
const unsigned short DOCUMENT_NODE = 9;
const unsigned short DOCUMENT_TYPE_NODE = 10;
const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
const unsigned short NOTATION_NODE = 12;
These are scriptable in NN6 as static properties of the Node object e.g.
Node.ELEMENT_NODE
Node.ATTRIBUTE_NODE
Unfortunately IE5 is neither exposing the Node object nor its static
properties so with IE5 you are forced to hard code the constants'
values.
~ ~ ~
In DOM-compliant browsers (IE5/NN6), you can retrieve (but not set) the
type of the given node in the following notation:
iType = oNode.nodeType
where iType specifies an integer (as shown in the above table)
indicating the nodeType of the requested node, which also determines
the valid values for the node, and whether the node can have child
nodes. The property is read-only.