Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 324
user701510 Avatar asked Dec 03 '22 06:12

user701510


1 Answers

http://jsfiddle.net/wWHux/3/

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

like image 97
Esailija Avatar answered Dec 19 '22 13:12

Esailija