Better JavaScript Links

Quirksmode website logoLet's assume you have already forgetten that you should be writting unobtrusive JavaScript. Or maybe you are just cleaning up some code you've inherited, but you aren't ready to go full-banana on Behaviour, etc. Well, at least remember to change the way you are used to generating those JavaScript link tags:

<a href="javascript:doSomething()">Do Something</a>

...To something like this:

<a href="#" onclick="doSomething();return false">Do Something</a>

Note the "return false" call at the end of the onclick attribute value. This is to prevent the jump-to-the-top-of-the-page effect when users click the link.

Hat tip to quirksmode for their early event handlers post.


Post a Comment

Aaron Hursman
Aaron Hursman is a passionate user-advocate who is lucky enough to do what he loves for a living. As a user experience architect, he applies user-centered design principles and techniques including user research, persona development, information architecture, storyboards, wireframes, prototyping, visual design, graphic design, interaction design, and usability. Aaron has a background in web development, enterprise applications, and the social web. At nGame, he is applying his craft to design and build the next generation of enterprise software. Aaron is available as a speaker and author upon request.
Disclaimer: The information in this website is provided "as is" with no warranties, and confers no rights. This website does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All instructions and code samples (if any, ever) are provided "as is" without warranty of any kind, either express or implied.