EvanBot Robot

jQuery Delay

A simple jQuery plugin that allows you to add a delay between jQuery functions. This small but very useful plugin that has saved me a lot of time. I haven't done a lot of testing, but because the plugin is so small and simple (only 212 bytes!) I don't think I could have missed much!

// Wait for #link to be clicked...
$("#link").click(function(){

  // Delay 1 second...
  $(this).delay(1000,function(){

    // Then display #hello
    $("#hello").css("display","block");

    // Then delay another 3 seconds...
    $(this).delay(3000,function(){

      // Change text color to blue
      $("#hello").css("color","blue");

    });
  });
});

UPDATED 06/14/2009: A newer version of this plugin is available! Get it

Download

Comment

See what others have to say on this topic, or add your own two cents.

View Comments (36) Post Comment