PDA

View Full Version : DOM in firefox



raghu207
Mar 16th, 2007, 03:07 PM
Hi all!

I had a very odd problem in firefox.. Here goes..

<td><input type="checkbox" id="chk" /></td>
<td><span>Some text</span></td>
<td><div>Some other stuff</div></td>

I tried accessing the div by first accessing the checkbox...

ele=document.getElementById('chk');
elediv=ele.parentNode.nextSibling.nextSibling.firstChild;

Donno why, but it doesnt work... The fix I used for this is to bring the table data into a single line:

<td><input type="checkbox" id="chk" /></td><td><span>Some text</span></td><td><div>Some other stuff</div></td>


Now it works! I'm very curious, how did this happen? (btw, it works just fine in IE 6 even before the 'fix')

Bill Posters
Mar 16th, 2007, 03:54 PM
The white space used in your formatting is considered a node by FF's more strict interpretation.

You'll need to build in a check to see if the nextSibling node is text, or rather, not an element…
e.g.

// if nodeType is text
if (nodeType == 3)

- or -

// if nodeType is not an element
if (nodeType != 1)
…and, if it is, move on to the next nextSibling node.

More info:
http://www.agavegroup.com/?p=32

HTH

raghu207
Mar 17th, 2007, 02:33 PM
ohhh yeaahhh....
firefox and some older opera browsers consider white space as text node...

Cool. Thanks for clearing it up! :)