I have a button on a page whose onclick funtion is posted below. I am
basically trying to get all the spans in the page and list them in 2
columns. I get the list of spans using getElementsByTa gName('span').
I dont want to move the spans themselves into my 2 column list(i.e I
want them to stay where they are on the page), so I figured I needed
to clone each span. Each time I make a clone, the clone somehow gets
added to my original list of spans, so I end up in an infinite loop
adding the first few elements again and again. How is this supposed to
be done? Javascript n00b here...any advise is greatly
appreciated...
function getSpans()
{
var allspans=docume nt.getElementsB yTagName("span" );
var infoDiv = null;
var tmp;
for(var element, i=0;element=all spans[i];i++)
{
tmp=element.clo neNode(true);
alert(i +' '+tmp.innerHTML +' ' +allspans.lengt h); <<<<<
allspans keeps increasing
if( i%2 == 0 ){
if( i!=0 ) list1.appendChi ld(infoDiv);
infoDiv=documen t.createElement ('div');
}
infoDiv.appendC hild(tmp);
}
}
list1 is a div id
Thanks
basically trying to get all the spans in the page and list them in 2
columns. I get the list of spans using getElementsByTa gName('span').
I dont want to move the spans themselves into my 2 column list(i.e I
want them to stay where they are on the page), so I figured I needed
to clone each span. Each time I make a clone, the clone somehow gets
added to my original list of spans, so I end up in an infinite loop
adding the first few elements again and again. How is this supposed to
be done? Javascript n00b here...any advise is greatly
appreciated...
function getSpans()
{
var allspans=docume nt.getElementsB yTagName("span" );
var infoDiv = null;
var tmp;
for(var element, i=0;element=all spans[i];i++)
{
tmp=element.clo neNode(true);
alert(i +' '+tmp.innerHTML +' ' +allspans.lengt h); <<<<<
allspans keeps increasing
if( i%2 == 0 ){
if( i!=0 ) list1.appendChi ld(infoDiv);
infoDiv=documen t.createElement ('div');
}
infoDiv.appendC hild(tmp);
}
}
list1 is a div id
Thanks
Comment