Search code examples
javascripthtmlhref

What is javascript:;?


In some sites I noticed the following href:

<a href="javascript:;">Link</a>

I'm interested in what javascript:; means? Is it the same as javascript:void(0)?


Solution

  • javascript: means "whatever comes after this will be javascript."

    ; ends the javascript statement.

    Therefore yes, it does absolutely nothing.

    Why not just use <a href="#">foo</a> then?

    Simply put, using # will have bad consequences if you've set a <base> HTML tag, and in most cases it will scroll to the top of the page unless you have onclick="return false;".