I created a function in javascript that i add to an anchor as such
javascript :
somefunction = function () {alert(\'foo\')}
html :
I know that the question is asked for JavaScript, but if anyone would like to do it in jQuery then it is pretty simple.
You can give your a tag an id and reference it in jQuery to do a certain action.
All you need to do, - to avoid the scroll to top is to disable the default action of the a tag.
Code:
$( "#a-tag-id" ).click(function(e) {
e.preventDefault();
alert( "Hello World" );
});