Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] looping through nodeList


  • From: hassan at webtuitive.com (Hassan Schroeder)
  • Subject: [Javascript] looping through nodeList
  • Date: Tue Oct 18 14:28:08 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@xxxxxxxxxxxxxx
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                          dream.  code.