Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with setTimeout "function is not define" !

problem with setTimeout "function is not define" !

What is the problem in this code ?

$(document).ready(function(){ 

 function ISS_NextImage() { //ImageSlideShow NextImage
  $('.ImageSlideShow').each(function() {
   alert($(".correntImage", this).text());
  });
 }

 var t=setTimeout("ISS_NextImage();",1000);

});
like image 791
faressoft Avatar asked Sep 20 '10 21:09

faressoft


3 Answers

When you eval code, it is done in the global scope. Since the function you are trying to call is locally scoped, this fails.

Pass the function to setTimeout instead of passing a string to be evaled.

var t=setTimeout(ISS_NextImage,1000);
like image 113
Quentin Avatar answered Oct 17 '22 04:10

Quentin


Try changing your set timeout call to this:

var t=setTimeout(function(){ISS_NextImage();},1000);
like image 42
mcgregok Avatar answered Oct 17 '22 02:10

mcgregok


Avoid passing a string to setTimeout(). Just pass a reference to the function instead:

var t = setTimeout(IIS_NextImage, 1000);
like image 36
istruble Avatar answered Oct 17 '22 03:10

istruble