The diary of your average web developer
26
Aug
2008
Posted under: Client Script
Tags: ,

Don’t you hate it when you need to do something so basic that you just can’t fathom the best way to achieve it? No? OK, it’s just me then.

What if you’ve just got a basic HTML anchor that you want to run some JavaScript event off, such as onclick, but don’t want the browser to go to the ‘top’ of the page when actioned? The following will shift to the top of the page when clicked:

<a href="#" onclick="alert('Clicked');">Click me</a>

but the following will not, as expected:

<a href="javascript:void(0);" onclick="alert('Clicked');">Click me</a>

Simple when you know how!

Share this post:
  • Facebook
  • del.icio.us
  • Digg
  • StumbleUpon
  • Technorati
  • Google
  • Reddit

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment