It's precisely for this reason that the DOM offers a faster and moreefficient method of accessing elements within the page - thegetElementById() method. I've rewritten the example above to demonstrate how this method can be used.
As you can see, this is much simpler to read...and code. Every node has some basic properties which come in handy for the developer- for example, the "nodeName" property returns the tag name, while the"nodeType" property returns a number indicating the type of node (HTMLtag=1; HTML tag attribute=2; text block=3). If the node happens to be atext node rather than a tag, the "data" and "nodeValue" properties returnthe text string. The following example demonstrates how the various node properties can beaccessed - uncomment the various alert() method calls to display thevarious object properties.
And incidentally - a text node which contains no data returns the value"#text" to the "nodeName" property - try replacing the line of text fromwithin the <font> tags above with a couple of blank spaces to see what I mean.
blog comments powered by Disqus |
|
|