7

I want to force a function to wait 1 second before she continues after to do that in javascript . For example:

function DoSomething(){
// wait 1 second
//continue w.e is this function does.
}

Thanks.

Ori Refael
  • 2,476
  • 3
  • 27
  • 60

1 Answers1

13

If i understand you right , you need this:

setTimeout(DoSomething ,1000);

Edit , thanks to Teemu:

function DoSomething (){
    setTimeout(ContinueDoSomething ,1000);
}
function ContinueDoSomething (){
    // ...
}

And even one more way , may be most effective in some cases:

function DoSomething (){
    setTimeout( function(){
        // ...
    },1000);
}
Community
  • 1
  • 1
Ivan Chernykh
  • 38,282
  • 12
  • 125
  • 141