Jump to content

dealing with getElementsByTagName


ohdang888

Recommended Posts

i'm using getElementsByTagName to grab all links and go through them and alert their ids

 

Its working fine, except for the fact that it goes through the first link on the page 4 times...

 

in other words, instead of alerting like this:

1

2

3

 

it alerts like this:

1

2

3

1

1

 

var links = document.getElementsByTagName("a");

for (var x in links)
{
var link = links.item(x);
alert(link.id);
}

 

and this

 

<a href="index1.php" id="1">1</a>
<a href="index2.php" id="2">2</a>
<a href="index3.php" id="3">3</a>

 

Any ideas?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/159094-dealing-with-getelementsbytagname/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.