JavaScript url that will go nowhere

in «tip» by Michael Beard
Tags: , , , ,

Description

How to have url that underlines a link, but goes nowhere when clicked on.

What it solved

Just need a way to have a "link" that shows the underline (default) behavior of the browser, to show that there is a link, but when you click on it, it does nothing.

How do I make a link that goes nowhere? does the trick. I used a combination of two answers: leepowers (most votes for answer, but some caveats) and Mystical (one that I've used before and like better, as it shows intent).

leepowers' answer:

<-- will add to the browser history ->
<a href="#"></a>

<-- won't add to the browser history (preferred method): ->
<a href="javascript:;"></a>

Mystical's answer:

<a href="javascript:void(0);">Click on this JavaScript error-free link that won't change your URL nor save it into your browser history</a><hr />
<a href="#void">Maybe a more readable approach, but unfortunately this one changes your URL</a>

Anyway, I needed this for a Dojo widget that defaulted a url to something that would cause the least harm and be something that would still highlight/underline the link label.

I think that the void(0); signals better intent than just ;, but that's my opinion.