Solved

Changing childNode text.

Posted on 2003-10-24
3
1,822 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

628 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