As onclickyou do return false;at the end to prevent the default action, which in this case actually moves in the URL-address, for example:
document.getElementById('linkId').onclick = function() {
alert("This link would go to: " + this.href);
return false;
};
, - jQuery event.preventDefault():
$("a").click(function(e) {
alert("This link would go to: " + this.href);
return false;
});