-4

How can do this please help me

these buttons remove With 1 second

Remove Button

var i=0;
while(i<10) {
  var itemDivs = document.getElementsByClassName("remove");
  itemDivs[i].style.display = 'none';
  a++;
  sleep(1000); // is not working. I want wait 1 seconds and continue loop
}
Oriol
  • 225,583
  • 46
  • 371
  • 457
cihan
  • 1
  • 1

1 Answers1

0

You would want to use the setTimeout function.

this function takes two arguments, the time in milliseconds, and a callback function.

To achieve a sleep type method I would suggest changing your for loop, to a function, and then use the setTimeout function to refer back to your function.

EX:

var i=0;
function foo() {`enter code here`
    i++;
    if(i<10) {
        itemDivs[a].style.display = 'none';
        a++;
        setTimeout(1000,foo); //Notice there are no parentheses after the function being passed into setTimeout.
    }
};
Balake
  • 169
  • 7