[Javascript] looping through nodeList
Hassan Schroeder
hassan at webtuitive.com
Tue Oct 18 14:12:04 CDT 2005
Anthony Ettinger wrote:
> Can't seem to get this down, I get an HTML object, but
> it's length is zero.
>
> var anchors = document.getElementsByTagName("a");
> alert(anchors); // yields [object HTML Collection]
>
> for (anchor in anchors)
> {
> var item = anchor;
> alert(item); //yields length, item, namedItem
> (once)
> }
You want something like:
for ( var count = 0; count < anchors.length; count++ )
{
var item = anchors[count];
alert(item.getAttribute("href")); /* or whatever */
}
HTH!
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
dream. code.
More information about the Javascript
mailing list