Hi,
I have a need to attach event handlers to an anchor surrounding a image. The HTML is something like this:
<a href="http://a.com">
<img src="/images/go.gif"/>
</a>
At the end of the source, I have a piece of javascript that assigns the onclick event to onclick event of the anchor.
When the event handler gets executed as you click on the image on the browser, the 'srcElement' attribute you retrieve from the event object is the image, not the anchor. What I want is to retrieve the href of the anchor. I can't understand why the srcElement is the img though.
I tried to pass an argument to the event, but I don't know how to accomplish that. I cannot find an example on how to pass arguments to an event handler programmatically. The following won't work.
anchors.onclick = function(anchor) {
window.location = anchor;
doLoad();
}
Any advice?
Thanks in advance.
I have a need to attach event handlers to an anchor surrounding a image. The HTML is something like this:
<a href="http://a.com">
<img src="/images/go.gif"/>
</a>
At the end of the source, I have a piece of javascript that assigns the onclick event to onclick event of the anchor.
When the event handler gets executed as you click on the image on the browser, the 'srcElement' attribute you retrieve from the event object is the image, not the anchor. What I want is to retrieve the href of the anchor. I can't understand why the srcElement is the img though.
I tried to pass an argument to the event, but I don't know how to accomplish that. I cannot find an example on how to pass arguments to an event handler programmatically. The following won't work.
anchors.onclick = function(anchor) {
window.location = anchor;
doLoad();
}
Any advice?
Thanks in advance.

