Possible Duplicate:
setTimeout in a for-loop and pass i as value
i am trying generate dynamic array and using this array as loop .. but in loop settime out is not working or function is not working. Here is my code
jQuery(document).ready(function () {
temp = new Array();
generateArray(temp);
function generateArray(temp) {
if (temp.length < 10) {
res = randomXToY(1, 10, 0);
for (var k = 0; k < temp.length; k++) {
if (temp[k] == res) {
var test = 1;
}
}
if (test != 1) {
temp.push(res);
//abc(temp);
}
generateArray(temp);
} else {
for (var z = 0; z < 10; z++) {
tnest(temp[z]);
setTimeout(function () {
removeClassImg(temp[z])
}, 3000);
}
temp = new Array();
generateArray(temp);
}
}
function removeClassImg(result1) {
alert(result1);
$('#img' + result1).fadeTo(12000, 0.1);
return true;
}
function tnest(result) {
alert(result);
$('#img' + result).fadeTo(12000, 1);
return true;
}
function randomXToY(minVal, maxVal, floatVal) {
var randVal = minVal + (Math.random() * (maxVal - minVal));
return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
}
});
alert in function removeClassImg is not working .. i am using settimeout in for loop this is not working fine.