jQuery: Wait/Delay 1 second without executing code

Brian Graham picture Brian Graham · Jan 17, 2012 · Viewed 449.9k times · Source

I can't get the .delay method working in jQuery:

$.delay(3000); // not working
$(queue).delay(3000); // not working

I'm using a while loop to wait until an uncontrolled changing value is greater than or equal to another and I can't find any way to hault execution for X seconds.

Answer

Matt Sich picture Matt Sich · Jul 21, 2012

You can also just delay some operation this way:

setTimeout(function (){

  // Something you want delayed.

}, 5000); // How long do you want the delay to be (in milliseconds)?