Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing childNode text.

Posted on 2003-10-24
3
Medium Priority
?
1,824 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 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

885 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