<html>
<head>
<script type="text/javascript">
function test() {
for (var i=0; i<10; i++) {
setTimeout( function() {
alert("execution " + i)
}, 1000 )
}
}
test()
</script>
</head>
<body>
</body>
<html>
I am searching for a way to delay a function's execution;
the problem is a bit more complex but it can be resumed to
the inline function I wrote in this example.
I need to delay a function with some seconds, but I can not
manage to save the context and so when the function is
called, the delayed action only applies to the last element
(here only alerts "execution 10" instead of "execution
0"... "execution 1" ... etc).
<head>
<script type="text/javascript">
function test() {
for (var i=0; i<10; i++) {
setTimeout( function() {
alert("execution " + i)
}, 1000 )
}
}
test()
</script>
</head>
<body>
</body>
<html>
I am searching for a way to delay a function's execution;
the problem is a bit more complex but it can be resumed to
the inline function I wrote in this example.
I need to delay a function with some seconds, but I can not
manage to save the context and so when the function is
called, the delayed action only applies to the last element
(here only alerts "execution 10" instead of "execution
0"... "execution 1" ... etc).