HighDots Forums  

appendChild problem... please help...

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss appendChild problem... please help... in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Julius Mong
 
Posts: n/a

Default appendChild problem... please help... - 11-05-2004 , 04:11 AM






Hi all, I'm reading an XML file and populating an <OL> in the HTML file
using the XML data. I grab the number of <DATA> elements in the flat XML
tree and then remove any existing <LI>s from the previous run and populate
the <OL> with new elements that I create. However it fails on the line where
stories.appendChild(newLi) in the 2nd for loop. It gives an error of
"Invalid argument". I don't understand why it is doing this, cos' if I
comment that line out it compiles fine, and newLi does appendChild fine
there... I tried checking no of kids of newLi and it says 1 which is
correct. However stories just won't appendChild... please enlighten... :-(

var x = xmlDoc.getElementsByTagName('DATA');

var stories = parent.pg_right.document.getElementById("stories") ;

var kids = stories.childNodes.length;

for (var i = kids-1 ; i >= 0 ; i-- ) {
var li = stories.childNodes[i];
stories.removeChild(li);
}

for ( var k=0 ; k<x.length ; k++ ) {
var newLi = document.createElement("li");
var txtLi = document.createTextNode(" ");
newLi.appendChild(txtLi);
stories.appendChild(newLi);
}

Thanks,

Jules



Reply With Quote
  #2  
Old   
Julius Mong
 
Posts: n/a

Default Re: appendChild problem... please help... - 11-05-2004 , 10:05 AM






sorted

"Julius Mong" <jxm96c (AT) hotmail (DOT) com> wrote

Quote:
Hi all, I'm reading an XML file and populating an <OL> in the HTML file
using the XML data. I grab the number of <DATA> elements in the flat XML
tree and then remove any existing <LI>s from the previous run and populate
the <OL> with new elements that I create. However it fails on the line
where stories.appendChild(newLi) in the 2nd for loop. It gives an error of
"Invalid argument". I don't understand why it is doing this, cos' if I
comment that line out it compiles fine, and newLi does appendChild fine
there... I tried checking no of kids of newLi and it says 1 which is
correct. However stories just won't appendChild... please enlighten... :-(

var x = xmlDoc.getElementsByTagName('DATA');

var stories = parent.pg_right.document.getElementById("stories") ;

var kids = stories.childNodes.length;

for (var i = kids-1 ; i >= 0 ; i-- ) {
var li = stories.childNodes[i];
stories.removeChild(li);
}

for ( var k=0 ; k<x.length ; k++ ) {
var newLi = document.createElement("li");
var txtLi = document.createTextNode(" ");
newLi.appendChild(txtLi);
stories.appendChild(newLi);
}

Thanks,

Jules




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.