Href="javascript:void(0);" or omit href attribute all together?

I typed in <a href=“javascript:void(0);”> when I realised… why? It’s going to be a clickable link that triggers a javascript event.

Wouldn’t it be better to simply omit the href attribute, it’s not required after all. It seems the only reason to include the href is to force the hand cursor. Since this is possible with CSS is there any semantic or compatibility reason to include the href attribute at all?

Further to that: Should it even be an <a> tag or should I just use a clickable div/li/whatever the parent element is?

I’m interested in the best practice pros/cons of it.

[font=verdana]The main reason for keeping the script activation in an <a> tag is to ensure that it is accessible for keyboard navigation and other assistive technology (including some mobile devices), which usually won’t allow anything other than a link or input to receive focus, meaning that if you have the script activation on a <div> or other element, it will be impossible for people without a mouse or certain touch-screen devices to activate it.

I’m not aware of any advantage of including href="javascript:void(0);" or even just href="#", although it may be that some devices won’t allow keyboard-users to tab to an <a> that doesn’t have an href.

Of course, what you should try to ensure in most cases is that you have a non-scripted fallback for people not running Javascript, which would of course use the href.[/font]

What Stevie said ^

I’d only add that having a proper URL in the href to that content also helps people like me who like to right click > open in new tab. It does depend on what you are showing on click though.

Anyone with JavaScript disabled who clicks on the link will need a proper URL in the link as their destination.

If you don’t want people with JavaScript disabled to click on the link thyen you should be adding the link itself using JavaScript. Then you can use href=“” since you know that it will never be used.