
Client-side JavaScript
|
45
The IE 4 DOM also includes the related outerHTML property,
which replaces the element and its content, and the
insertAdjacentHTML() and insertAdjacentText() methods.
These are not as commonly used, nor as commonly imple-
mented outside of IE as
innerHTML; you can read about them
in the reference section under Element.
DOM compatibility
If you want to write a script that uses the W3C DOM when it is
available, and otherwise uses the IE 4 DOM if it is available, you
can use a capability-testing approach that first checks for the exist-
ence of a method or property to determine whether the browser has
the capability you desire. For example:
if (document.getElementById) {
// If the W3C method exists, use it
}
else if (document.all) {
// If the all[] array exists, use it
}
else {
// Otherwise use the legacy DOM
}
DHTML: Scripting CSS Styles
DHTML, or Dynamic HTML, is the result of combining
HTML, CSS, and JavaScript: it uses scripts to dynamically
modify the style—which may include the position and visi-
bility—of document elements. In the W3C and the IE 4
DOMs, every document element has a
style property that
corresponds to the HTML
style attribute that specifies inline
styles. Instead of referring to a simple string, however, the
style property refers to a Style object that has properties cor-
responding to each of the CSS attributes of the style.
For example, if an element
e has a style ...