I have an event handler that is called six times when I click on a link.
var elems = elem.getElementsByTagName('a');
var cntr = 0;
for(var a in elems) {
AttachEvent(elems[cntr], 'click', function(e) {
this.reporturl = this.href;
document.getElementById('reportpopup').style.visibility = "visible";
return false;
});
}
I am using Firefox 3.5 currently so this is used for AttachEvent:
function AttachEvent(obj,evt,fnc,useCapture){
if (!useCapture) useCapture=false;
if (undefined == obj || null == obj)
return;
if (obj.addEventListener){
obj.addEventListener(evt,fnc,useCapture);
return true;
} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
else{
MyAttachEvent(obj,evt,fnc);
obj['on'+evt]=function(){ MyFireEvent(obj,evt); };
}
}
The this.href
value is the same each time, and there are only three links that match my getElementsByTagName
.
So, I have attached an event to my link, and when I click on one of the three, it is called six times with the exact same link information.
Any idea why this may be happening?