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);
});
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);
});
Share
Improve this question
asked Sep 20, 2010 at 21:36
faressoftfaressoft
19.7k44 gold badges107 silver badges149 bronze badges
5 Answers
Reset to default 12When 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 eval
ed.
var t=setTimeout(ISS_NextImage,1000);
Try changing your set timeout call to this:
var t=setTimeout(function(){ISS_NextImage();},1000);
Avoid passing a string to setTimeout(). Just pass a reference to the function instead:
var t = setTimeout(IIS_NextImage, 1000);
you could also:
$(function() {
var t = setTimeout(new function() {
$('.ImageSlideShow').each(function() {
alert($(".correntImage", this).text());
});
}, 1000);
});
You could do something like this:
$(document).ready(function(){
setTimeout(ISS_NextImage,1000);
});
function ISS_NextImage() {
$('.ImageSlideShow').each(function() {
alert($(".correntImage", this).text());
});
}