
Client-side JavaScript
|
43
function embolden(node) { // Embolden node n
var b = document.createElement("b");
var p = n.parentNode; // Get parent of n
p.replaceChild(b, n); // Replace n with <b>
b.appendChild(n); // Insert n into <b> tag
}
IE 4 DOM
The IE 4 DOM was introduced in Version 4 of Microsoft’s
Internet Explorer browser. It is a powerful but non-standard
DOM with capabilities similar to those of the W3C DOM. IE
5 and later include support for most basic W3C DOM fea-
tures, but this documentation on the IE 4 DOM is included
because IE 4 is still commonly used. The following subsec-
tions document the IE 4 DOM in terms of its differences
from the W3C DOM, so you should be familiar with the
W3C DOM first.
Accessing document elements
The IE 4 DOM does not support the getElementById()
method. Instead, it allows you to look up arbitrary docu-
ment elements by
id attribute within the all[] array of the
document object:
var list = document.all["mylist"];
list = document.all.mylist; // this also works
Instead of supporting the getElementsByTagName() method,
the IE 4 DOM takes the unusual step of defining a
tags()
method on the all[] array, which exists on document ele-
ments as well as the Document object itself. Here’s how to
find all
<li> tags within the first <ul> tag:
var lists = document.all.tags("UL");
var items = lists[0].all.tags("LI");
Note that you must specify the desired HTML tag name in
uppercase ...