Link to home
Start Free TrialLog in
Avatar of Xxavier
XxavierFlag for Canada

asked on

Changing childNode text.

<p id="n1">AAAAAA<em>BBBBBB</em>CCCCCC<em>DDDDDD</em>EEEEEE</p>

I have the above

alert(document.getElementById("n1").childNodes.length)

gives me 5 as I would expect

document.getElementById("n1").childNodes[0].nodeValue="XXXXXX"

changes AAAAA to XXXXX as I would expect, as does using firstChild

but

document.getElementById("n1").childNodes[1].nodeValue="XXXXXX"

does nothing and printing out the nodeValue gives NULL. I am a bit rusty with this stuff and am trying to access the  2nd node with value BBBB, or I am up a conceptual gum tree here? ie change BBBBB to XXXX. I know I can give it an id and access it that way but can I access as a childnode of n1?

ASKER CERTIFIED SOLUTION
Avatar of devic
devic
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And that is correct behaviour under DOM rules. Element has nodeValue of NULL.
Avatar of Xxavier

ASKER

Thanks that makes sense now.