Sleep in JQuery? Sleep in JQuery? jquery jquery

Sleep in JQuery?


For your specific function .show() isn't queued, but there's an easy trick to make it queued so you can use .delay(), like this:

$('#div1').hide();$("#div2").delay(1000).show(0);

By giving it a 0 duration argument, it's now an instant, but queued animation. Underneath this uses setTimeout(), so it's basically the same behavior as:

$('#div1').hide();setTimeout(function() { $("#div2").show(); }, 1000);


Here ya go!

$('#div1').hide();//sleep or wait or for a sec setTimeout('moomoo()', 1000);function moomoo() {  $("#div2").show();}


The following should do what you want:

$("#div1").hide();$("#div2").delay(1000).show(0);