DOM question

A

Ang Talunin

Hey,

I've got this code:

var dataDate =
document.createTextNode(x[q].childNodes[3].firstChild.nodeValue);
var dataBody =
document.createTextNode(x[q].childNodes[4].firstChild.nodeValue);

and the first line works fine...but the second gives this error:
x[q].childNodes[4].firstChild.nodeValue has no properties

They are defined almost the same in the xml and i can't find the error

anybody got a idea?

A.T.

ps. Mozilla gives the errors MIE not....
 
Y

Yann-Erwan Perio

Ang said:
x[q].childNodes[4].firstChild.nodeValue has no properties
ps. Mozilla gives the errors MIE not....

User agents treat white-spaces/new-lines differently, some add text
nodes, some do not. Either remove any ws-nl, or (better) adopt a more
defensive coding approach, don't use indexes, use tree walkers with
filters or IDed elements.


Regards,
Yep.
 
D

DU

Ang said:
Hey,

I've got this code:

var dataDate =
document.createTextNode(x[q].childNodes[3].firstChild.nodeValue);
var dataBody =
document.createTextNode(x[q].childNodes[4].firstChild.nodeValue);

and the first line works fine...but the second gives this error:
x[q].childNodes[4].firstChild.nodeValue has no properties

They are defined almost the same in the xml and i can't find the error

anybody got a idea?

A.T.

ps. Mozilla gives the errors MIE not....

What Yann-Erwan Perio replied you is correct.

http://www.mozilla.org/docs/dom/technote/whitespace/

DU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top