|
-
Sep 20th, 2005, 09:35 AM
#1
Thread Starter
Not NoteMe
[Javascript] Getting contents of an element in a node list
I've read in an XML document and have got a node list using getelementsbytagname.
This works ok as the length of the nodelist is 18, which is right having checked the xml document i'm reading in.
Trouble is, i can't workout how to access the contents of the element, i.e.
<title mode="escaped" type="text/html">Long time no see</title>
I've tried the following, but nothing works. (i'm testing using the alert statement).
MyNodeList.item(0).value
MyNodeList.item(0).innerHTML
I've also tried accessing other elements besides 0.
When i do alert(MyNodeList.item(0)) it correctly displays a message box containing [Object Element], so i know the element's there!
Any help would be greatly appreciated!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Sep 21st, 2005, 08:55 AM
#2
Lively Member
Re: [Javascript] Getting contents of an element in a node list
What happends when you do:
alert(MyNodeList.item(0).childNodes[1].firstChild.nodeValue);
-
Sep 21st, 2005, 10:38 AM
#3
Re: [Javascript] Getting contents of an element in a node list
That is because the node contains another node. A text node object which is dreived from a node object. To access it you need to to do the following:
Code:
MyNodeList.item(0).childNodes[0].nodeValue
-
Sep 21st, 2005, 05:55 PM
#4
Thread Starter
Not NoteMe
Re: [Javascript] Getting contents of an element in a node list
Cool that works, thanks Adam.
Just a quick question though, am i right in thinking that you can only get the innerHTML of a leaf element then?? If so, what if i want just a branch of the document tree???
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|