As already mentioned in the previous phrase, it is possible to gather information about a node, which is extremely useful when working on arbitrary DOM data. Whereas nodeName gives information about the name of the node (tag name or #text for text nodes), nodeValue is useful only for text nodes and returns the actual text in the node. The third category of information comes from the nodeType property, which gives information regarding the kind of node. Table 5.1 contains a list of all possible values for nodeType.
The following code then analyzes a simple DOM structure and outputs information regarding all child nodes. Figure 5.2 shows the output in the browser. Retrieving Node Information (nodeinfo.html)
Figure 5.2. Information about all child nodes. |