DOM Compatibility with Internet Explorer 4
Although IE 4 is not DOM-compliant, it has features that are similar to the core DOM APIs. These features are not part of the DOM standard and are not compatible with Netscape, but they are compatible with later versions of IE. The features are summarized here; consult the client-side reference section of this book for more details.
Traversing a Document
The DOM standard specifies that all
Node objects, which includes both the Document object and all Element
objects, have a childNodes[]
array that contains
the children of that node. IE 4 does not support
childNodes[]
, but it provides a very similar
children[]
array on its Document and HTMLElement
objects. Thus, it is easy to write a recursive function like the one
shown in Example 17-1 to traverse the complete set of
HTML elements within an IE 4 document.
There is one substantial difference between IE 4’s
children[]
array and the standard DOM
childNodes[]
array, however. IE 4 does not have a
Text node type and does not consider strings of text to be children.
Thus, a <p>
tag that contains only plain
text with no markup has an empty children[]
array
in IE 4. As we’ll see shortly, however, the textual content of
a <p>
tag is available through the IE 4
innerText
property.
Finding Document Elements
IE 4 does
not support the getElementById( )
and
getElementsByTagName( )
methods of the Document
object. Instead, the Document object and all document elements have
an array property named
all[] ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.