Dumb question about <a> and onclick

I have a dumb js question that has bothered me for quite some time but i never took the time to look into…

if I have a link (<a> tag) that I am just using to trigger a javascript action, I usually will say

<a href=“#” onClick=“some_js_code”>link text</a>

when i view the page and click this link, it jumps me to the top of the page which is annoying if the javascript i am triggering is something that triggers an animation at the current location (jquery slideDown or something)

I have gotten around this before with something liek this:
<a name=“someName”></a>
<a href=“#someName” onClick=“some_js_code”>link text</a>

but there has to be a better way… is there something else I can put in the href attribute to avoid this jumping to the top of the page?

add return false to the end of the JavaScript to disable the href.

of course that still leaves the 10% of people without JavaScript with a link that does nothing so you might consider having the link actually go somewhere that provides an equivalent option for them.

so then:
<a href=“#” onClick=“some_js_code; return false;”>link text</a>

is that about right?

Yes. That will revent the href running for those with javaScript enabled.

looks like it worked like a champ - thanks!!