Free web host - 239Chapter 15Generic HTML Element ObjectsTable 15-5: W3C DOM

239Chapter 15Generic HTML Element ObjectsTable 15-5: W3C DOM nodeType ConstantsReferencenodeType ValueNode.ELEMENT_NODE1Node.ATTRIBUTE_NODE2Node.TEXT_NODE3Node.CDATA_SECTION_NODE4Node.ENTITY_REFERENCE_NODE5Node.ENTITY_NODE6Node.PROCESSING_INSTRUCTION_NODE7Node.COMMENT_NODE8Node.DOCUMENT_NODE9Node.DOCUMENT_TYPE_NODE10Node.DOCUMENT_FRAGMENT_NODE11Node.NOTATION_NODE12ExampleYou can experiment with viewing nodeTypeproperty values in The Evaluator. The pelementwhose ID is myPis a good place to start. The pelement itself is a nodeTypeof 1: document.getElementById( myP ).nodeTypeThis element has three child nodes: a string of text (nodeName#text); an emelement (nodeNameem); and the rest of the text of the element content (nodeName#text). If you view the nodeTypeof either of the text portions, the value comes back as 3: document.getElementById( myP ).childNodes[0].nodeTypeRelated Item:nodeNameproperty. nodeValueValue:Number, string, or null.Read/Write Compatibility:WinIE5+, MacIE5+, NN6+, Moz1+, Safari1+ For a text node, the nodeValueproperty consists of the actual text for that node. Such a nodecannot contain any further nested elements, so the nodeValueproperty offers another wayof reading and modifying what Internet Explorer implements as an element s innerTextprop- erty (but in the W3C DOM you must reference the child text node of an element to get or setits node value). Of the node types implemented in the W3C DOM capable browsers, only the text and attributetypes have readable values. An element s node value returns a nullvalue. For an attributenode, the nodeValueproperty consists of the value assigned to that attribute. According tothe W3C DOM standard, attribute values should be reflected as strings. WinIE5, however, returns values of type Numberwhen the value is all numeric characters. Even if you assign astring version of a number to such a nodeValueproperty, it is converted to a Numbertypeinternally. NN6 and MacIE5 return nodeValuevalues as strings in all cases (and convertnumeric assignments to strings). elementObject.nodeValue