title: how to add onclick event on anchor tag that is generated with javascript?
body: <p>I'm using only javascript, not jQuery or no other javascript frameworks.</p>
  
  <p>I have created one anchor tag like:</p>
  
  <pre><code>var _a = document.createElement('a');
  </code></pre>
  
  <p>now I want to add onclick for this tag. I have tried following:</p>
  
  <pre><code>_a.onclick = function(){ mycode(id); }
  </code></pre>
  
  <p>The function applies on that but the anchor tags are create in loop... so <code>mycode(id)</code> is always taking the last value of the loop.</p>
  
  <p>Can any one help me out in this ?</p>