[X]

The javascript: URL

browser tricks 1996 partly

Putting code in the href, which then has to return nothing or it replaces the page.

In 2026: Still works in an href and is a bad idea. If the expression returns a value, the browser navigates to it as a document, which is why every one of these ends in void(0) or a function with no return. Use an onclick handler, or a real button.

Where it came from: Netscape Navigator 2.0 JavaScript documentation, 1996. Wikipedia

<!-- The three forms you will find in old markup -->
<a href="javascript:void(0)" onclick="doThing()">Nothing in the href</a>
<a href="javascript:doThing()">Code in the href, relies on doThing returning nothing</a>
<a href="#" onclick="doThing(); return false">Hash plus return false</a>

<!-- What happens when the expression DOES return something -->
<a href="javascript:'hello'">Click this and the page becomes the word hello</a>

<script language="JavaScript">
function doThing() { alert("clicked"); }
</script>

<!-- The 2026 version -->
<button type="button" onclick="doThing()">A button, which is what this always was</button>
sandboxed demo · breaks nothing but itselfrestart

More in browser tricks

all 25 in browser tricks › · the whole library ›