Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting IDs with getElementsByTagName

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
How do I get the ID of the element using getElementsByTagName?
example:
Code:
images = getElementsByTagName("img");
for(i=0;i<=images.length;i++){
  alert (images.id);
}

_______________
_brian.
 
make 2 small changes:
Code:
images = getElementsByTagName("img");
[gray][i]//note the <= changed to <[/i][/gray]
for(i = 0; i < images.length; i++){
  alert (images[!][i][/!].id);
}

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
bdichiara, did that fix your problem?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
yeah, that seemed to work, but i had to move it to the end of the document. if i put some functions after it, does it matter where on the page the functions are? (i.e. before or after [tt]<body>[/tt] tag or just before [tt]</body>[/tt] tag...

_______________
_brian.
 
It shouldn't matter where the functions are declared as long as they are in <script> tags.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top