href javascript ; void 0

The void oper­a­tor is often used to obtain the undefined prim­i­tive value.

<a href="javascript:void(0);">
  Click Me
</a>

In this case, it is used to avoid # in the URI bar.

The hrefs value will be undefined. Hence, when user clicks on the Click Me link, the URI will remain the same in the address bar.


Alter­na­tives:

<a href="#" onclick="return false;">
  Click Me
</a>
<a href="#" onmousedown="return false;">
  Click Me
</a>

The return false pre­vents the page from being nav­i­gated and unwanted scrolling of a window.


You may also like...