Image container instead of event object in image load event handler
I stumbled upon a very strange thing. In FF 3.6 (not tested others yet) I add onload handler to an image like this:
imgRef.addEventListener("load", activateLink, false);
When load event fires, in activateLink(evt) the evt paramater is not an event, but the "a" tag that contains the image. Why is this?
function activateLink(evt) {
// evt turns out to be a refference to <a> tag (HTMLAnchorElement) that contains the image.
// Actually two of them. Both dynamically added with addElement.
}
I remembered another fact that may be relevant. I have multiple images with the same src 开发者_如何学Pythonthat all have registered this same event handler activateLink. Could this be the problem?
I found the cause, I actually call this method by myself with the a tag as parameter. Forgot to change the reference on one place. Stupid javascript and its loose types :( Stupid mistake.
精彩评论