No... you don't put the onclick handler on the link either. Keep your JS out
of your HTML.

If it's a link that's ONLY there for the JS to do something, insert the link
with the JS.
If it's a link that can degrade gracefully (the preferred scenario), then
put the link in, then override it's action.

Whether the link is a full link, an anchor link, or just a dummy # link,
return false (or, in jquery, preventDefault();) will prevent it from
scrolling or otherwise causing you trouble.

This is basic unobtrusive scripting.


On 2/16/07, Kenneth <[EMAIL PROTECTED]> wrote:

I actually prefer javascript:; since using # usually scrolls the page to
the top which can be really annoying. If it's not a real link I don't see
what the problem is there.

Now, if it's an actual link that you're wanting to apply an onclick
function to, you should use the onclick="javascript:return myfunc();"
attribute, use the normal URL in the href="", and then return true/false
from myfunc() depending on whether or not you want to link to be activated
by the click.

On 2/16/07, hcabbos <[EMAIL PROTECTED]> wrote:
>
> What's the best way to apply a behavior to an anchor tag?
>
> <a href="#" class="someClass">my text</a>
>
> -- or --
>
> <a href="javascript:;" class="someClass">my text</a>
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to