According to jQuery document on .delay()
,
The .delay() method is best for delaying between queued jQuery effects. Because it is limited
As far as I understand, .delay()
is meant specifically for adding a delay between methods in a given jQuery queue. For example, if you wanted to fade an image into view during the span of 1 second, have it visible for 5 seconds, and then spend another second to fade it out of view again, you could do the following:
$('#image').fadeIn(1000).delay(5000).fadeOut(1000);
In this instance, .delay()
is more intuitive to use since it is specifically meant for delaying events in a given jQuery queue. setImeout()
, on the other hand, is a native JavaScript method that isn't intended explicitly for a queue line. If you wanted an alert box to pop up 1 second after clicking on a button, you could do the following:
function delayAlert() {
var x = setTimeout("alert('5 seconds later!')", 5000);
}