Search code examples
javascriptjquerytimeoutsleeptiming

javascript timeout/sleep using setTimeout()


How can I set a 2 second timeout to wait for page controls to be populated? I want to use javascript I have tried the following but to no avail:

setTimeout(function(){},2000);

setTimeout(2000);

Anyone able to provide a pointer?


Solution

  • setTimeout(function(){
      //put your code in here to be delayed by 2 seconds
    },2000);
    

    The code you want to delay needs to sit inside the setTimeout function.