Javascript – tell anything about a hyperlink that was clicked in JavaScript

htmljavascriptjavascript-events

If I have code like this:

<script>
function determine()
{
    // ????
}
</script>

<a href="blah1" onclick="determine()">blah1</a>
<a href="blah2" onclick="determine()">blah2</a>

Is there a way in determine() to see which link was clicked?

(Yes, I know, the easy and correct thing to do would be to pass "this" to determine()…but in this case that's not going to be easy to do because of legacy code issues.)

EDIT: I probably should have mentioned this at the beginning…our site is not currently using (and cannot use, for the time being) JQuery…so JQuery answers (while valuable in general for this type of question) won't actually help me.

Best Solution

Check out this link from quirksmode. You can get the event target.

function doSomething(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
}