Timeout doesn't work

function updateimage(){
 $("#fileimg").attr("src","secondimage.jpg");
 $('#fileimg').fadeIn('slow');
}
setTimeout(updateimage(), 5000);

This is the code i tried. Its a code to reload the image every 5 seconds. But it doesn't work. I get this error in IE: Invalid argument Can y'all help me? Thanks.

Answers


2 options.

setTimeout("updateimage()", 5000)

or

setTimeout(function() {
    updateimage();
}, 5000);

You should pass the actual function as argument and not the call:

setTimeout(updateimage, 5000);

Try

setTimeout('updateimage()', 5000);


Need Your Help

Designers to Developers-What should I know?

design client protocols

This is a broad question, so let me narrow it a bit. I am a graphic designer entering the world of web design. I'm not totally green in this field, but I know enough to know that I have a lot to le...

Why is my CalendarExtender getting overlapped when rendered?

asp.net-ajax calendarextender

I'm working on a .NET web application and I'm using a CalendarExtender control within it to have the user specify a date. For some reason, when I click the icon to display the calendar, the backgro...

Practical examples of use for Clojure's new some-> macro

clojure

Clojure 1.5 adds new threading macros, including: