Solved

Changing childNode text.

Posted on 2003-10-24
3
1,813 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now