title: Assign click handlers in for loop
body: <p>I'm having several div's <code>#mydiv1</code>, <code>#mydiv2</code>, <code>#mydiv3</code>, ... and want to assign click handlers to them:</p>
  
  <pre><code>$(document).ready(function(){
    for(var i = 0; i &lt; 20; i++) {
      $('#question' + i).click( function(){
        alert('you clicked ' + i);
      });
    }
  });
  </code></pre>
  
  <p>But instead of showing <code>'you clicked 3'</code> when click on <code>#mydiv3</code> (as for every other click) I get <code>'you clicked 20'</code>. What am I doing wrong?</p>