title: What is the best way to execute a function when user clicks on a link?
body: <p>From my experience I know three different ways to execute a JavaScript function when a user clicks on a link</p>
  <ol>
  <li><p>Use the <code>onclick</code> attribute on the link</p>
  <pre><code> &lt;a href=&quot;#&quot; onclick=&quot;myfunction();return false;&quot;&gt;click me&lt;/a&gt;
  </code></pre>
  </li>
  <li><p>Use the <code>href</code> on the link</p>
  <pre><code> &lt;a href=&quot;javascript:myfunction();&quot;&gt;click me&lt;/a&gt;
  </code></pre>
  </li>
  <li><p>Don't touch the link, do everything in js</p>
  <pre><code> &lt;a href=&quot;#&quot;&gt;click me&lt;/a&gt;
  </code></pre>
  <p>(in the JavaScript we will stop the default event, and call the function)</p>
  </li>
  </ol>
  <p>Which one is better? What are the advantages and disadvantages?</p>
  <p><strong>EDIT</strong> deleted the &quot;javascript:&quot; on <code>onclick</code></p>