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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.