469,271 Members | 1,718 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

What is the DOM difference between IE and FF in this code?

<div id="alertBox" style="position: absolute; border:1px dashed;
z-index:2">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>THE TITLE </td>
</tr>
<tr>
<td>CONTENT</td>
</tr>
</table>
</div>

When I get the object:
myObject = document.getElementById('alertBox');
alert(myObject.childNodes.length)

I found that there are 3 nodes in FF and only 1 node in IE6,
FF got: Text Node, Table Node, Text Node,
IE got: Table Node

Is it the property of the browser?

Aug 7 '06 #1
1 1546
Cylix wrote:
<div id="alertBox" style="position: absolute; border:1px dashed;
z-index:2">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>THE TITLE </td>
</tr>
<tr>
<td>CONTENT</td>
</tr>
</table>
</div>

When I get the object:
myObject = document.getElementById('alertBox');
alert(myObject.childNodes.length)

I found that there are 3 nodes in FF and only 1 node in IE6,
FF got: Text Node, Table Node, Text Node,
IE got: Table Node

Is it the property of the browser?
Yes. The Gecko rendering engine (used in Firefox, Mozilla, et al)
maintains whitespace in the source HTML by inserting textnodes.

There is quite a bit of debate over this behaviour, however it is not
likely to change.

<ORL: https://bugzilla.mozilla.org/show_bug.cgi?id=26179 >
When navigating down the DOM tree, you always need to check the node
type to see if it's what you expect or a text node. If you remove the
whitespace between the closing tag of one element and the opening tag of
the next, Firefox will not insert the extra text nodes, e.g.:

<div id="alertBox" ... ><table ... ><tbody>
But depending on that is likely to create a maintenance hazard.
--
Rob
Aug 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Jason Huang | last post: by
12 posts views Thread by Nathan Sokalski | last post: by
9 posts views Thread by mistral | last post: by
49 posts views Thread by Zach | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.