#6 link with void operator as href value

submitted on by Sarah

Bad code

<a href="javascript:void(1)" onClick='window.location="index.html"'>Link</a>

Issues and how to fix them

  1. Links won't work, if JavaScript fails to load or execute.
  2. You don't need JavaScript to link to other pages, you can use the href attribute for that. Browser support is pretty good (100% of all browsers).
  3. The context menu on right click is different, "Open in new tab/window" is not available.
  4. CMD + Click to open a link in the background won't work.

Good code

<a href="index.html">Link</a>