JQuery delay() not delaying

delay will never delay regular methods - only those who are pushed to the animation/effect chain. If you want to delay your html() call, use queue ( http://api.jquery.com/queue/ ):

$('#error_box_text').html('error text').delay(5000).queue(function() {
   $(this).html('')
});

It would be nice if you could do

$('#error_box_text').html('error text').delay(5000, function() { $(this).html('') });

but this isn't possible (yet).


Try

var sel = $('#error_box_text');
sel.html('error text');
setTimeout(function(){
    sel.html('');
}, 5000);

See delay()

jQuery.delay() is best for delaying between queued jQuery effects and such, and is not a replacement for JavaScript's native setTimeout function

Tags:

Jquery