ProAnswers.org

Href for JavaScript links: "#" or "javascript:void(0)"?

When building a link that has the sole purpose to run JavaScript code, is it better to

Link

or

[Link](javascript:void(0))

?

1 Like

Neither.

	If you can have an actual URL that makes sense use that as the HREF. The onclick won't fire if someone middle-clicks on your link to open a new tab or if they have JavaScript disabled.



	If that is not possible, then you should at least inject the anchor tag into the document with JavaScript and the appropriate click event handlers.



	I realize this isn't always possible, but in my opinion it should be striven for in developing any public website.



	Check out: [http://en.wikipedia.org/wiki/Unobtrusive_JavaScript](http://en.wikipedia.org/wiki/Unobtrusive_JavaScript)



	and



	[http://en.wikipedia.org/wiki/Progressive_enhancement](http://en.wikipedia.org/wiki/Progressive_enhancement)