Variable keeps staying to one value
<p>I have a loop which im trying to make onclicks with their own ID number but it keeps updating to the last number in the loop - im wondering how i can stop it over writing the variable so they keep their own number?</p>

<p>This is what i have:</p>

<pre><code>count = 0;
for(i in my_array){ 
    if(my_array[i][2])){ //if the data value is true
        document.getElementById('div_id_'+count).onclick = function()
        {
            alert(i);
        };
    count++;
    }   
}
</code></pre>

<p>Thing is alert(i) always shows the last value of my_array... so im wondering how i can stop it over writing each time so each div can parse their own value?    </p>
