Make a clickable link with onclick but without href=#?
You can use CSS to force the cursor to change on hover of the clickable element:
.myClickableThingy {
cursor: pointer;
}
And then you can switch back to <span>
s or whatever of element you were using before <a>
tags.
You need to stop the browser from doing it's default action.
<a href="#" onclick="IDClick(id);event.preventDefault();">id</a>
When you click on a link, the default action is to go to that address. event.preventDefault();
prevents the browser from doing the default action.
This is a significantly better solution for accessibility. Quoting @aij's comment above: "using CSS makes it look ok, but still leaves it inaccessible from the keyboard (ie, tab will never focus the link)".
Give your anchor element a class and style it to achieve what you need:
<a class='kinda-link' onclick='whatevs()'>Hi I'm a kinda-link</a>
And your css:
a.kinda-link:hover { cursor: pointer; }