...

Traversing the 'getElementsByTagName' collection.

Leithakor
01-27-2003, 10:34 PM
Ok simply question, hopefully, simple answer.

How would I go about using the document.getElementsByTagName in a reference sense.

ie: placing a specific collection type into an array, so I can actually see the id's and such of all the referenced items (such as DIV's).

So that if I, for instance, use the following make believe function name "getAll('div')" it'll return an alert with the follow information

You searched for the following 'tag-type' of "DIV". These are the only elements with the DIV tag:

divId1, divID2, divID3, divID4,etc.,etc.,etc.

Hopefully you can see where I'm going with this. Main reason for this type of script is for debugging (say for misspelled div names and I can't find out where they are). Any help would be appreciated


Leithakor

jkd
01-27-2003, 10:40 PM
var divs = document.getElementsByTagName('div');
var message = 'There are ' + divs.length + '<div>\'s in this page with the following ids:\n';
for (var i = 0; i < divs.length; i++)
message += divs.item(i).getAttribute('id') + '\n';

alert(message);

Leithakor
01-28-2003, 03:52 AM
Excellent. Thank you very much =) Not certain why I didn't think about that. Very much appreciated.


Leithakor



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum