webwrks
webwrks

Reputation: 11918

jQuery - Delayed HTML function

I have an issue with doing two .html()'s in the same function cause the first one is getting overrun by the second. Any thoughts? This function is getting called when another action is taken, it is working fine, but when I put in the delay and the 2nd html() it doesn't work. Thanks.

function confirmNote() {
    $('#noteConfirm').html('Note Sent').delay(1000).html('Leave a Note');
}

Upvotes: 0

Views: 65

Answers (2)

Jack Franklin
Jack Franklin

Reputation: 3765

function confirmNote() {
    $('#noteConfirm').html('Note Sent')
    setTimeout(function() {
        $('#noteConfirm').html('Leave a Note');
    }, 1000);
}

Should do the trick. delay only delays animation so is not appropriate in this case.

Upvotes: 1

jfriend00
jfriend00

Reputation: 707496

.delay() only works with functions that go through the animation queue which does not include .html(). You can use a setTimeout() to do what you want.

function confirmNote() {
    $('#noteConfirm').html('Note Sent');
    setTimeout(function() {$('#noteConfirm').html('Leave a Note')}, 1000);
}

Upvotes: 3

Related Questions