This is an issue with Javascript executing linearly on a single thread.
using
setTimeout(function(){},time);
is evaluated and executing the function() immediately.
I am looking for a method to execute function() in x seconds, for example after the dom has been updated from an ajax call.
How is this done?
In other words just need to ‘pause’ the script and then let it know when to execute.
for clarity if you did something like this inside the function();
var a= document.getElementbyId("anid").innerHTML;
var a will be gathered at time setInterval is processed and not in x seconds when the function is executed.
Thanks…
It is better that you execute your function after the ajax call finishes. You can register a success/failure function that will get called once the call finishes. That is the right way to do it.
Here is an example with jquery:
** EDIT **
Removed the suggestion to pass the callback function as a string based on Quentin’s comments below, as it is indeed not a good practice.