Solved

Changing childNode text.

Posted on 2003-10-24
3
1,819 Views
Last Modified: 2008-02-01
<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?

0
Comment
Question by:Xxavier
3 Comments
 
LVL 25

Accepted Solution

by:
devic earned 125 total points
ID: 9619342
document.getElementById("n1").childNodes[1].childNodes[0].nodeValue="XXXXXX"
0
 
LVL 12

Expert Comment

by:ahosang
ID: 9619389
And that is correct behaviour under DOM rules. Element has nodeValue of NULL.
0
 
LVL 7

Author Comment

by:Xxavier
ID: 9619540
Thanks that makes sense now.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question