I have an anchor that doesn’t go anywhere but has an onclick (e.g. <a onclick="..."></a>). My question pertains to the href attribute. What should I put for the value?
If I simply omit href, the anchor doesn’t have the appropriate decoration–the mouse pointer icon doesn’t change when the mouse is put over it.
If I use href="#", then the window scrolls to the top of the page when the link is clicked.
If I use href="javascript:..." and put the value of onclick proceeding javascript:, the page is left and the address bar contains the Javascript when the link is clicked.
When I refer to browser behavior, I’m referring to Chrome, which I’m testing it in to start with.
What should I be putting for href when the anchor isn’t an actual link but exists only to have the onclick perform behavior?
In your onclick handler, add this to the end:
This will cancel the default processing (i.e. following the link) and you can put whatever you want in the href (the # is as good as any).