I can't get the .delay
method working in jQuery:
$.delay(3000); // not working
$(queue).delay(3000); // not working
I'm using a while loop to wait until an uncontrolled changing value is greater than or equal to another and I can't find any way to hault execution for X seconds.
delay()
doesn't halt the flow of code then re-run it. There's no practical way to do that in JavaScript. Everything has to be done with functions which take callbacks such assetTimeout
which others have mentioned.The purpose of jQuery's
delay()
is to make an animation queue wait before executing. So for example$(element).delay(3000).fadeIn(250);
will make the element fade in after 3 seconds.You can also just delay some operation this way:
es6 setTimeout
Edit: 204586560000 ms is the approximate time between the original question and this answer... assuming I calculated correctly.
Only javascript It will work without jQuery
jQuery's
delay
function is meant to be used with effects and effect queues, see thedelay
docs and the example therein:If you want to observe a variable for changes, you could do something like
Javascript is an asynchronous programming language so you can't stop the execution for a of time; the only way you can [pseudo]stop an execution is using setTimeout() that is not a delay but a "delayed function callback".