I'm trying to find the location of an element on the screen using javascript. This is what I'm doing.
function locateTargets(){
var targets = document.getElementsByTagName("span");
for(var i = 0;i<targets.length;i++){
if(targets[i].className == "target"){
targetsY[targets[i].getAttribute("id")] = targets[i].offsetTop;
}
}
}
This works fine in Firefox, Chrome and IE, but Opera and Safari end up finding 0 for all but the last element.
Any ideas why this might be happening and how to fix it?