Here's my code:
===
var content = document.getElementById('content');
var collection = content.getElementsByTagName('div');
for (var i = 0; i < collection.length; i++) {
alert(collection[collection.length - i - 1].id);
}
//Replace the above loop with this one, then run again
for (var i = 0; i < collection.length; i++) {
alert(collection[i].id);
}
===
The first for-loop displays the id of every div in the collection. The
second for-loop displays the id of each div as being 'undefined'.
Ultimately, I want to change a style of the div that matches a certain
ID, but the objects in 'collection' don't seem to have any attributes
except 'id'.
Why does the loop work backwards but not forwards? And why aren't the
objects in the collection typical elements? I've tested this code in
both Firefox and IE6. Both exhibit the same behavior.