setTimeout ignores timeout? (Fires immediately) [duplicate]
Solution 1:
You need to get rid of the parentheses on doFade()
.
The parentheses invoke the function instantly.
Just use this in stead: doFade
Solution 2:
setTimeout(doFade(), 500);
This line says "execute doFade()
, then pass whatever value it returns to setTimeout
, which will execute this return value after 500 milliseconds." I.e., you're calling doFade()
right there on the spot.
Skip the parentheses to pass the function to setTimeout
:
setTimeout(doFade, 500);
Solution 3:
I think you should use setTimeout(doFade, 500);
or setTimeout("doFade()", 500);