Jump to content

DOM question, arrayOfnodes.childNodes[0] != arrayOfnodes[0] ?!


arianhojat

Recommended Posts

I was trying to debug this error and i coulda swore i used childNodes[0] many times be4 without it failing.

but the code is rather simple so childNodes is probably the problem...

 

i am looking at this xml in my response var...

<info><isDirector>false</isDirector></info>

 

When my js code gets executed and arrives at this line it automatically quits...

var isDirector = response.getElementsByTagName('isDirector').childNodes[0].firstChild.nodeValue;

 

Cuts off without any javascript error in FireFox (errrr I really hate DOM errors like that).

 

i noticed however this works...

var isDirector = response.getElementsByTagName('isDirector')[0].firstChild.nodeValue;

 

 

i assumed getElementsByTagName returns an array of the html/xml collection and u probably should use childNodes syntax to drop into the xml node, and get its child node and then its text node value. Why should the array syntax be working better than the more appropriate xml syntax to get the child node?

 

thanks!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.