Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call js-function using JQuery timer

People also ask

How do I call a function after 2 seconds in jQuery?

To call a jQuery function after a certain delay, use the siteTimeout() method. Here, jQuery fadeOut() function is called after some seconds.

How can we call a function automatically after waiting for some time in jQuery?

Answer: Use the jQuery delay() method You can use the jQuery delay() method to call a function after waiting for some time. Simply pass an integer value to this function to set the time interval for the delay in milliseconds.

How do you run a function every 5 seconds?

To call a JavaScript function every 5 seconds continuously, we call setInterval with the function that we want to run and the interval between runs. const interval = setInterval(() => { // ... }, 5000); clearInterval(interval); to call setInterval with the callback we want to run and 5000 millisecond period.


You can use this:

window.setInterval(yourfunction, 10000);

function yourfunction() { alert('test'); }

window.setInterval(function() {
 alert('test');
}, 10000);

window.setInterval

Calls a function repeatedly, with a fixed time delay between each call to that function.


Might want to check out jQuery Timer to manage one or multiple timers.

http://code.google.com/p/jquery-timer/

var timer = $.timer(yourfunction, 10000);

function yourfunction() { alert('test'); }

Then you can control it with:

timer.play();
timer.pause();
timer.toggle();
timer.once();
etc...

setInterval is the function you want. That repeats every x miliseconds.

window.setInterval(function() {
    alert('test');
}, 10000);

jQuery 1.4 also includes a .delay( duration, [ queueName ] ) method if you only need it to trigger once and have already started using that version.

$('#foo').slideUp(300).delay(800).fadeIn(400);

http://api.jquery.com/delay/

Ooops....my mistake you were looking for an event to continue triggering. I'll leave this here, someone may find it helpful.