Monday, May 7, 2007

javascript:void(0) is meaningless

If you are absolutely going to use <a> to create non-linking functionality, chances are that you are using custom event handlers and adding an href="javascript:void(0)" attribute so that IE will play nicely with the CSS :hover pseudo-element.

The problem with that is that javascript:void(0) says absolutely nothing about what the custom anchor does. All it does is return undefined.

A better cheap trick to tell your user what the anchor does is to use a javascript label. Like so:

<a href="javascript:ShowBooks:">View</a>

For the javascript runtime, the label is an empty instruction, which returns undefined, just like void(0), but with the added benefit that it can be used to make the status bar more user-friendly.

No comments:

Post a Comment