title: How to add ondblclick on an image with Javascript in a loop?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/341723/event-handlers-inside-a-javascript-loop-need-a-closure">Event handlers inside a Javascript loop - need a closure?</a>  </p>
  </blockquote>
  
  
  
  <pre><code>for i = 1 to 5
  {
   var el = document.createElement('img');
   el.ondblclick = somefunction();
   mydiv.appendChild(el);
  }
  </code></pre>
  
  <p>Seems el.ondblclick = somefunction('test'); doesn't do any insertion.</p>
  
  <p>I know I can do..</p>
  
  <pre><code>el.ondblclick= function() { somefunction('test') };
  </code></pre>
  
  <p>.. but that doesn't work in a loop!</p>