setTimeout function jQuery

If you are thinking to perform some operation(s) after some specified interval of time, then jquery setTimeout function is ready to do the job for you.

setTimeout function

setTimeout() accepts two arguments.

  1. The function that you want to execute after specified delay.
  2. The duration of delay in milliseconds

In the above example code, myFunction is the one which I wanted to execute after 2 seconds.

In another way, one can also use anonymous function(if not want to define the function separately) and define login in setTimeout as follows:

setTimeout() is a basic JavaScript function, actually. Do not confuse setTimeout() with setInterval() function. The difference between the two is that setTimeout() executes once after specified time, while setInterval() repeats the execution of function.