title: How should I call my JavaScript. href, onclick or bind the click event?
body: <p>I know there are already a lot of articles about this concept but my question has a little difference.</p>
  <p>On my page, I have a link:</p>
  <pre><code>&lt;a id=&quot;mylink&quot;&gt;click me &lt;/a&gt;
  </code></pre>
  <p>Then I'm changing the href dynamically using:</p>
  <pre><code>$get('mylink').href = 'javascript:doSomething(id);';
  </code></pre>
  <p>It happens I have to call the above code multiple times so I overwrite the current value of the href attribute with JavaScript code calling the same function with different id parameter.</p>
  <p>The above is what I'm using for a long time now, but the mess started some time ago when I'm trying to implement <code>OnNavigateAway</code> to warn the user when they closes the browser window. IE will also trigger this <code>onNavigateAway</code> event when the user clicks a anchor with a value for the href attribute.</p>
  <p>So I started to replace those href's with jQuery click events:</p>
  <pre><code>$(&quot;#mylink&quot;).click(function (e) {
  doSomething(id);
  e.preventDefault();
  });
  </code></pre>
  <p>But remember that this code can be called multiple times, so I have to unbind the click event first and then bind again:</p>
  <pre><code>function completed(result) { 
  $(&quot;#mylink&quot;).unbind('click'); 
      $(&quot;#mylink&quot;).click(function (e) {
      doSomething(result.id);
      e.preventDefault();
      });
  }
  </code></pre>
  <p>Is this a good way to handle my JavaScript? Or is this binding and unbind stuff no good practice?</p>
  <p>Another way to do this can be to overwrite the <code>onclick</code> attribute manually with JavaScript.</p>
  <p>How would you handle this?</p>
  <p>I'm looking forward to your response.</p>