Reputation: 109
I added a delay but it is not working...
<div id="sum"></div>рублей
$('#sum').html('3000').delay(3000).html('5000');
Why is delay not working?
Upvotes: 2
Views: 93
Reputation: 263167
delay() only affects the animation queue, and html() does not use that queue.
However, you can call queue() and invoke html()
from its callback function to achieve the effect you want:
$("#sum").html("3000").delay(3000).queue(function() {
$(this).html("5000").dequeue();
});
You will find an updated fiddle here.
Upvotes: 3
Reputation: 337733
delay()
applies to actions stored in the queue - such as animations. html()
does not use the queue, therefore the code above does not behave as you expect.
For non-queued actions, you will need to use setTimeout()
to delay execution. Try this:
$('#sum').html('3000');
setTimeout(function() {
$('#sum').html('5000');
}, 3000);
Upvotes: 2