title: How to create javascript delay function
body: <p>I have a javascript file, and in several places I want to add a small delay, so the script would reach that point, wait 3 seconds, and then continue with the rest of the code. The best way that I thought of doing this was to create a function, which I could call from anywhere in the script.</p>
  
  <pre><code>function startDelay(lengthOfDelay)
  {
  //code to make it delay for lengthOfDelay amount of time
  }
  </code></pre>
  
  <p>However, I can not find any way to implement the code to make it wait. I had a look at setTimeout, but you needed to hard code the function into it, which made it no good for me.</p>
  
  <p>Is there any way that I can get the script to juct pause for a few seconds? I have no problem with the UI freezing whilst the code is paused.</p>
  
  <p>If not, is there a way that I could use the PHP <strong>sleep()</strong> to achieve this? (I know that PHP is server side and Javascript is client side, but maybe there is a way that I have not heard of.)</p>