-2

How call JavaScript functions in time interval. I want call a function with time interval how can I done that

1

1 Answer 1

0

If you want to call it after a certain time interval you can do something like this (this will do it after 3 seconds);

setInterval(MyFunc, 3000); 

setInterval() has a signature that is a function being the first parameter and the interval in milliseconds as the second parameter (thus the amount of seconds is equal to 3000/1000 as there are 1000 milliseconds per second). SetInterval will also call that function over and over again every 3 seconds! So make sure you want it to!

For example if you wanted to show an alert you could do:

setInterval(function() { alert("Hello World") }, 3000); 

If you want it to run only once just replace setInterval with setTimeout which will just run it once after the time given (again in milliseconds).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.