putting the js parts in the href
attribute is a bad idea. best practice is adding a handler with addEventListener
but here you can get away with setting onclick
directly.
<a href="#" onclick="Foo(event);">Link</a>
and your function would be like
function Foo(e) {
var a = e.target || e.srcElement;
// TODO: stuff
if (e.preventDefault) {
e.preventDefault();
}
else {
return false;
}
}
so when you click the link, Foo
is called with the event as a paremeter. the event object has a reference to the source element, either as target
in standards browsers or srcElement
in IE. the preventDefault
/return false;
combo at the end prevents the browser from "following" the link to #.
edit: on second thought, since you have many links, using jquery to add handlers the recommended way is probably better (although the first solution is still fine).
...
<a id="A5" href="#" >Link</a>
<a id="A6" href="#" >Link</a>
<a id="A7" href="#" >Link</a>
...
<script>
$('a').click(Foo);
</script>