javascript Node nodeType

来源:互联网 发布:php的正则表达式 编辑:程序博客网 时间:2024/05/22 16:45

Returns an integer that corresponds to a node type as specified in the W3C DOM. This is the preferred property to use to test a node object for its type (rather than the nodeName property values). Every node type has a value, but not all browsers that support the nodeType property support all node types as objects. The integer values have corresponding constants associated with them, which you can use to make more verbose, but easier-to-read script comparisons for node type processing (see the ATTRIBUTE_NODEproperty). Note that there is no way to distinguish element types (e.g., root Element node versus anHTMLElement node) via the nodeType property. Also note that IE 6 in Windows erroneously reports aDOCTYPE element as a comment node type.

 Example 
if (document.getElementById("elementID").firstChild.nodeType == 1) { // process as an element}
 Value

Integer values according to the following table.

 ValueNode typeW3C DOMIE/WindowsIE/MacNN1ELEMENT_NODE15562ATTRIBUTE_NODE16563TEXT_NODE15564CDATA_SECTION_NODE1n/an/an/a5ENTITY_REFERENCE_NODE1n/an/ana/6ENTITY_NODE1n/an/an/a7PROCESSING_INSTRUCTION_NODE1n/an/an/a8COMMENT_NODE16569DOCUMENT_NODE155610DOCUMENT_TYPE_NODE1n/an/a611DOCUMENT_FRAGMENT_NODE1n/an/a612NOTATION_NODE1n/an/an/a

原创粉丝点击