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?
This is what i have:
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++;
}
}
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?
if my_array is Object instead of Array