:::: MENU ::::

Javascript setTimeout() function jquery examples and chaining it with afterTime() plugin

jquery_logo

javascript setTimeout() function

  • It takes two arguments.
    1. callback function to execute after milliseconds supplied.
    2. milliseconds – after how many milliseconds callback function will execute?.
  • It’s asynchronous or non-blocking.

    i.e. next line after setTimeout executes immediately and doesn’t wait for callback to execute.

  • It returns handler that can be used to halt execution of setTimeout() function.

jQuery setTimeout() usage example

Button Code:-

Output:-

jQuery afterTime() method to chain setTimeout() function

jQuery afterTime() method can be used to chain with jQuery selectors

Sample Usage of this plugin

Demo

Further Chaining:-  it executes jQuery append() without waiting for afterTime() callback to finish.

Demo

 Chaining of afterTime() method to execute multiple setTimeout() synchronously.

 Demo

Share and Enjoy

  • DZone
  • Google Plus
  • LinkedIn
  • Twitter
  • Facebook
  • Email

So, what do you think ?

  •