javascriptjquerysleep

How to make a non-blocking sleep in javascript/jquery?


How to make a non-blocking sleep in javascript/jquery?


Solution

  • At the risk of stealing the answer from your commentors, use setTimeout(). For example:

    var aWhile = 5000; // 5 seconds
    var doSomethingAfterAWhile = function() {
      // do something
    }
    setTimeout( doSomethingAfterAWhile, aWhile );