S
sp1d3rx
-----------code:------------- (whitesmiths indentation)
function PopulateUlList()
{
alert("started populating...");
var ulz = inter.getElementsByTagName("ul");
alert(ulz.length);
for(x in ulz)
{
alert(ulz[x].id);
}
}
-------------html-------------
<div id='inter'>
<ul id="cute"></ul>
<ul id="ugly"></ul>
</div>
--------------------------
When this code is run in Firefox 2.0, it alerts the following...
"started populating..."
"2"
"cute"
"ugly"
"undefined"
"undefined"
Why does it say 'undefined' ? Also, changing the loop from a "for in"
to a "for" loop (for(x = 0; x < ulz.length; x++)), I no longer get the
problem. Why can't I use "for in" ?
function PopulateUlList()
{
alert("started populating...");
var ulz = inter.getElementsByTagName("ul");
alert(ulz.length);
for(x in ulz)
{
alert(ulz[x].id);
}
}
-------------html-------------
<div id='inter'>
<ul id="cute"></ul>
<ul id="ugly"></ul>
</div>
--------------------------
When this code is run in Firefox 2.0, it alerts the following...
"started populating..."
"2"
"cute"
"ugly"
"undefined"
"undefined"
Why does it say 'undefined' ? Also, changing the loop from a "for in"
to a "for" loop (for(x = 0; x < ulz.length; x++)), I no longer get the
problem. Why can't I use "for in" ?