A: 

Well... I'd say the reason it that it is IE. I don't think the programers had a specific intention to do it that way.

okoman
Well, I didn't mean "Why" in the "Why did they design it that way?" sense, I meant it in the "What is the correlation between these nodes to make them act this way?" sense.
zachleat
A: 

I'm guessing that the table tag is different between browsers.

e.g. which nodes does the default table auto-magically contain?

<table>
  <thead>
  </thead>
  <tbody>
  </tbody>
  <tfoot>
  </tfoot>
</table>
scunliffe
zachleat
A: 

Why not just try walking the DOM and see what each browser thinks that the document contains?

IE does a lot of "optimization" of the DOM. To get an impression of what this might look like, "Select all", "Copy" in IE, and then "Paste Alternate" in Visual Studio, You get the following:

<INPUT value="Submit Query" type=submit> 
<INPUT value=Reset type=reset> 
<INPUT type=button> 
<INPUT type=text> 
<INPUT value="" type=password> 
<INPUT type=file> 
<INPUT type=hidden>
<INPUT type=checkbox>
<INPUT type=radio>
<BUTTON type=submit></BUTTON> 
<SELECT></SELECT>
<TEXTAREA></TEXTAREA>

So it nukes some of the empty tags and adds some default attributes.

Ishmael
+3  A: 

IE tries to be helpful and hides text nodes that contain only whitespace.

In the following:

<p>
<input>
</p>

W3C DOM spec says that <p> has 3 child nodes ("\n", <input> and "\n"), IE will pretend there's only one.

The solution is to skip text nodes in all browsers:

var node = element.firstChild;
while(node && node.nodeType == 3) node = node.nextSibling;

Popular JS frameworks have functions for such things.

porneL
I've been running into a similar problem when trying to make my javascript code work in both FF and IE. This was very helpful.
Tony Peterson