Bug on getElementsByTagName in IE?

Hi,

im trying to run a script that runs in every browser except IE (IE 7)
this is part of the script:

function menuInteract()
{
var listLines = document.getElementsByTagName(“li”);
alert(listLines.length);
for (var i=0; i<listLines.length; i++){
attachEventListener(listLines[i], “mouseover”, rollOver, false);
attachEventListener(listLines[i], “mouseout”, rollOut, false);
}
}

the alert was to find why is not working.
On every other browser the alert(listLines.length) give me the number “16” that is the number of ‘li’ tags but in IE7 gives me [object] so as soon i get in the ‘for’ the scrip stop in IE.

Is this a bug or is there something that is missing in my code?

How do you have the attachEventListener() function defined?

I test it every line with “alert” until it breaks, and in IE it doesnt go inside of the ‘for’ so i dont think its from the attachEventListener

but here it is:

function attachEventListener(element, eventType, functionRef, capture) {
if (typeof element.addEventListener != “undefined”)
{
element.addEventListener(eventType, functionRef, capture);
}
else if (typeof element.attachEvent != “undefined”)
{
element.attachEvent(“on” + eventType, functionRef);
}
else
{
eventType = “on” + eventType;

if (typeof element[eventType] == "function")
{
  var oldListener = element[eventType];

  element[eventType] = function()
  {
    oldListener();

    return  functionRef();
  }
}
else
{
  element[eventType] = functionRef;
}

}

return true;
}

P.S - how can i format this text with indentation here?

In the advanced editing there is a syntax dropdown box you can choose from.

Normally you wrap the code with a highlight statement, where at the start of the code you place highlight=“javascript” inside square brackets, and at the end you place /highlight in square brackets.

Do you have anything else on the page that could be interfering with IE, such as a form element called length? A look at the offending page would do wonders towards helping you out.

[highlight=“javascript” ]

well at the moment im testing a beaviour in a navigation menu
so I cuted the all <ul> wraped with a div and that is all my html, so no I dont have any form there

but the situation here dont make sense because result of the array with all li’s tags in every browser is the same except in IE

var listLines = document.getElementsByTagName("li");
alert(listLines.length);

this alert gives the same number (on this case 16) in every browser except in IE (IE7) that give this info: ‘[object]’
So when it goes to the for

for (var i=0; i&lt;listLines.length; i++)

it make sense to break because IE cant count it, it return ‘[object]’ from the listLines.length

So just can be from the geElementsByTagName in my IE.
the question is: Is there a bug or its my IE that is jammed?

[/highlight ]

P.S. - The

 doesnt seem to work

Can someone help me please.

Is there a bug or not?
if it is i have to look other way to colect the LI’s

Can you Help me?

So is there a bug or not?

IE normally shows the length of a nodelist as a number, so if it’s showing for you as an object then something is wrong with your page.

Test code shows that there is no differnece in the way that IE normally works.


<html>
<head>
</head>
<body>
<ul>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
    <li>Line Item</li>
</ul>    
<script type="text/javascript">
var listLines = document.getElementsByTagName("li");
alert(listLines.length);
</script>
</body>
</html>

This means that there is something else on your page that is causing the interference.
Show it to us, and we’ll show you where the trouble lies.

it seems that the problem its solved.

I had in one li tag the id=“length” <li id=“length”>

Probably most be a conflit of names.

Can anyone confirm that. The word length canot be given as an id from an html tag?

Yes, that can be confirmed. I brought up the issue in message #5. IE plays silly buggers with identifiers and named elements. It’s most upsetting.

Thanks, I couldn’t understand initially