Duplicate ID/indexes and looping
- by Justin Alexander
I realize having two elements in the same html doc with the same ID is wrong, bad, immoral, and will lead to global warming. But... I'm trying to write an XSS widgit, so I really have no control over the quality of the parent web page.
I loop through document.images to retrieve a list of images on the page. I perform an action on each one.
for(img in document.images){
...
}
i've also tried
for(var i=0;i<document.images.length;i++){
...
}
in both cases it allows me to loop through all of the elements, BUT when trying trying to reference an object with a duplicate ID, I always get the first (in order of the html).
When using debugger in IE8 i'm able to see that both elements ARE listed, but that they both have the same index (in IE the index of the document.images is either sequential or matches the image ID)
Does anyone have a better solution?