wrote:
> Hi,
>
> I finally solved the problem. It had nothing to do with DOM
> initialisation at all. All the onload/setEventHandler/etc. stuff works
> ok. The problem (predictably) was an error on my part.
>
> Apparently IE and FF treat a table's children differently. Under IE the
> firstChild of a table is the first row, whereas under FF it's something
> else (maybe a a text node). So what happened was that one browser
> needed a firstChild, while the other required childNodes[1].
The firstchild of a table is never a TR, it is always either a CAPTION, COL
or COLGROUP, THEAD, TFOOT or TBODY.
A tbody must always be present, it will be added by the browser if you don't.
>
> I fixed the problem using:
> var feeTable = document.getElementById('feeTable');
> var rows = feeTable.rows; //instead of firstChild etc.
> which works ok under both. This was probably obvious to all of you in
> this ng but as I said I'm a Javascript novice.
It's actually a consequence of your HTML, you discovered it because of how
you were trying to access elements by traversing the DOM tree. Firefox
will insert text nodes where there is whitespace between elements[1], IE
generally doesn't. For example given the HTML:
<tr>
<td> ... </td>
</tr>
In Firefox the TR will have three child nodes, #text, TD then #text. In IE,
it will have just one - the TD. If the HTML was:
<tr><td> ... </td></tr>
both browsers will give the TR just one child - the TD. Using the rows
collection is much better.
Be aware that there might be browsers that don't support the rows
collection, there is at least one reasonably modern browser (Safari 1.0.3 -
Mac OS 10.2.

that only partially supports the row cells collection (fixed
in later versions). There are a number of mobile browsers that seem to
have very patchy W3C DOM support (even though they may be well be fully
compliant with JavaScript 1.5).
You could perhaps use getElementsByTagName or walk down the DOM tree
testing nodeName, tagName or nodeType.
1. "Between" being either:
- after the opening tag of an element and before the
opening tag of a child node,
- after the closing tag of an element and before
the opening tag of a sibling, or
- after the closing tag of an element and before the
closing tag of its parent element.
Use the Firefox DOM inspector to see where they are, there will be other
#text nodes amongst element contents.
--
Rob