user701510 user701510 - 1 year ago 127
Javascript Question

function in setInterval() executes without delay

I am in the process of making a jquery application to hide an image after a specified interval of time by using setInterval(). The problem is that the hide image function executes immediately without delay.

$(document).ready(function() {

setInterval(change(), 99999999);

function change() {
$('#slideshow img').eq(0).removeClass('show');



I am testing it in jsfiddle.

Answer Source

You called the function immediately instead of passing it to setInterval.

setInterval( change, 1500 ) - passes function change to setInterval

setInterval( change(), 1500 ) - calls the function change and passes the result (undefined) to setInterval

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download