In my JavaScript code, inside the setTimeout() the value of a variable btnIdValue
is not changing. It's showing a constant value 0. As this iterates through the loop the value was supposed to be changing. The minimum value for btnIdValue
is set to 1.
$('#clearBtn').click(function(){
btnIdValue = $('#inputTxtBx').val();
while( btnIdValue > 0 ){
setTimeout(function() {
alert(["#circle",btnIdValue].join(''));
$(["#circle",btnIdValue].join('')).remove();
$(["#button",btnIdValue].join('')).remove();
}, 1000);
alert(btnIdValue);
btnIdValue--;
}
});
I am trying to remove elements with id. When i issued the hard-coded values, it works.
$("#circle1").remove();
$("#button").remove();
I tried the below part inside a loop, but it removes all the elements without the desired delay and remove effect.
$(["#", btnIdValue].join('')).delay(1000).fadeOut(1000, function(){
$(this).remove();
});