title: What is the difference between the different methods of putting JavaScript code in an <a>?
body: <p>I have seen the following methods of putting JavaScript code in an <code>&lt;a&gt;</code> tag:</p>
  
  <pre><code>function DoSomething() { ... return false; }
  </code></pre>
  
  <ol>
  <li><code>&lt;a href="javascript:;" onClick="return DoSomething();"&gt;link&lt;/a&gt;</code></li>
  <li><code>&lt;a href="javascript:DoSomething();"&gt;link&lt;/a&gt;</code></li>
  <li><code>&lt;a href="javascript:void(0);" onClick="return DoSomething();"&gt;link&lt;/a&gt;</code></li>
  <li><code>&lt;a href="#" onClick="return DoSomething();"&gt;link&lt;/a&gt;</code></li>
  </ol>
  
  <p>I understand the idea of trying to put a valid URL instead of just JavaScript code, just in case the user doesn't have JavaScript enabled. But for the purpose of this discussion, I need to assume JavaScript is enabled (they can't login without it).</p>
  
  <p>I personally like option 2 as it allows you to see what's going to be run&ndash;especially useful when debuging where there are parameters being passed to the function. I have used it quite a bit and haven't found browser issues.</p>
  
  <p>I have read that people recommend 4, because it gives the user a real link to follow, but really, # isn't "real". It will go absolutely no where.</p>
  
  <p>Is there one that isn't support or is really bad, when you know the user has JavaScript enabled?</p>
  
  <p>Related question: <em><a href="https://stackoverflow.com/questions/134845/href-for-javascript-links-or-javascriptvoid0">Href for JavaScript links: “#” or “javascript:void(0)”?</a></em>.</p>