undefined variable when loop variable passed to callback function
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2520587/variable-in-javascript-callback-functions-always-gets-last-value-in-loop">Variable in JavaScript callback functions always gets last value in loop?</a>  </p>
</blockquote>



<p>I  am not able to pass the value of k to the callback function of fadeOut function.
my loop is as given below.</p>

<pre><code> for(var k=0;k&lt;image1.length;k++)
 {

    $(img[k]).fadeOut(200,function(k) {
        alert(k);
        $(this).attr('src', image2[k]);
        $(this).fadeIn(200);
    });
  }
</code></pre>
