WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 [ DOM ] node type, dreadcast, September 3, 2003
     Re:[ DOM ] node type, Chris, September 3, 2003
         Re:[ DOM ] node type, dreadcast, September 4, 2003
             Re:[ DOM ] node type, Erik Arvidsson, September 5, 2003

Subject: Re:[ DOM ] node type From: Erik Arvidsson Date: September 5, 2003
You could use a tree walker or node iterator (See W3C DOM level 2 specs). I have a tree walker for DOM level 1 compatible browsers. See http://webfx.eae.net/dhtml/treewalker/treewalker.js



That's what I fugured out...
But a one-line coded page isn't very handy so I've added :
if (document.getElementById('select1').childNodes[0].nodeType == 1)
alert (document.getElementById('select1').childNodes[0].id);

Thanks for helping
From: Chris
Sent: September 3, 2003
Subject: Re:[ DOM ] node type

Moz returns 'undefined' because the first childNode in

<div id="select1">
<div id="db1">tata</div>
<div id="db2">toto</div>
<div id="db3">titi</div>

is a text node since there is a new line between
<div id="select1">

<div id="db1">tata</div>

This is the 'correct' way of interpreting childNodes (see info on XML for more of an explanation).

So if childNodes[0] is a text node, it isnt going to have an id attribute...

use childNode[1] for Moz to get the HTMLDivElement you want and so get its id.

(this is also true for childNodes[2] etc... you need to go for the odd numbers to get all your DIV's...)

To keep the same code for referencing them, you could structure the divs like:

<div id="select1"><div id="db1">tata</div><div id="db2">toto</div><div id="db3">titi</div>.....</div>

so there's no white space between them...



Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.

View All Messages
Back to WebFX