PDA

View Full Version : IE wont do a node loop more than once?



Shard
July 10th, 2007, 07:02 AM
OK -I have an unordered list that that every list item contains an anchor within (a menu) and I need to loop thru it and alter the height of every anchor except the first one. I also need to ignore (from a node point of view) every even numbered node since they represent a text node. The code is as follows ....



bul = document.getElementById(subnav);
for(var b = 3; b < totalnodes; b++){
if(!isEven(b)){ // function test for even and odd numbering
temp = bul.childNodes[b].firstChild; // the anchor part of the li entry
tt = temp.offsetTop;
temp.style.top = (tt + heightCounter + gap) + "px";
heightCounter += (sublinkHeight + gap); // increment the height counter so the next one appears below it
}
}


In FF everything works fine (I can even trace/alert the vars all the way thru) but in IE it works only for the first loop (where b = 3). A trace shows all the same values as FF, but it just doesnt want to come back for more?????
Any clues???
Any help greatly appeciated cause soon I will animate that height adjustment (e.g. increment it slowly).

borrob
July 10th, 2007, 07:06 AM
where is totalnodes defined?

Shard
July 10th, 2007, 07:08 AM
where is totalnodes defined?

earlier on - sorry but I only posted the problem part of the code :-)
The heightCounter and gap etc are also declared earlier

borrob
July 10th, 2007, 07:29 AM
Found the problem:
the thing ie returns is a TextNode object and not a htmlelement and that has no offsetTop
so i think you'll have to find another solution....

you could try to alert the temp object and see if it's got a member data ( specific for the textnode ) so
alert( temp.data ); ( will alert the innerhtml or innerText of the textnode )

Shard
July 10th, 2007, 07:34 AM
Found the problem:
the thing ie returns is a TextNode object and not a htmlelement and that has no offsetTop
so i think you'll have to find another solution....

you could try to alert the temp object and see if it's got a member data ( specific for the textnode ) so
alert( temp.data );

cheers m8 - will give that a try - according to the DOM inspector in FF node 5 should be the same as node 3 but IE reckons its null. What I might do is when I calculate totalnodes - assign an id to all the hrefs at that time - would make it easier fo later.

Shard
July 10th, 2007, 07:46 AM
cheers m8 - will give that a try - according to the DOM inspector in FF node 5 should be the same as node 3 but IE reckons its null. What I might do is when I calculate totalnodes - assign an id to all the hrefs at that time - would make it easier fo later.

Yeap - much easier - now I can refer to the href within the li directly without having to naviagte the DOM tree ..


for(var i =0; i < ul.childNodes.length; i++){
if(ul.childNodes[i].nodeName == "LI" || ul.childNodes[i].nodeName == "li" ){
len++; ul.childNodes[i].firstChild.setAttribute ("id", "al" + i);
}
}

Shard
July 10th, 2007, 07:52 AM
Yeap - much easier - now I can refer to the href within the li directly without having to naviagte the DOM tree ..


for(var i =0; i < ul.childNodes.length; i++){
if(ul.childNodes[i].nodeName == "LI" || ul.childNodes[i].nodeName == "li" ){
len++; ul.childNodes[i].firstChild.setAttribute ("id", "al" + i);
}
}

Where's my manners - lol

Thanks for your time dude/dudette