Yes but, it gets tricky when using a parameter of the function that is setting the timeout as a parameter of the function set by the timeout. Think about it.
The problem is that the original function's parameter is a local variable or something like one. However, by the time the timeout fires, it is looking for its value in the global scope. This can be overcome by passing the original parameter as a local variable written to the timeout call as a literal:
Code:
function show(id, file) {
document.getElementById(id).src = file;
setTimeout("hide("+id+")", 1000);
}
or sometimes:
Code:
function show(id, file) {
document.getElementById(id).src = file;
setTimeout("hide('"+id+"')", 1000);
}
can be required.
Bookmarks