Jitender
Jitender

Reputation: 7969

.done after .animate callback function

I want call a function after .animate callback function. I am using .done method for this purpose but it is not working. fiddle

$(function(){
$('button').click(function(){
$('div').animate({width:'400px'},300,function(){alert(0)})
}).promise().done(function(){alert(1)})
})

Upvotes: 7

Views: 12195

Answers (2)

CodingIntrigue
CodingIntrigue

Reputation: 78575

You need to put the promise on the animate function. At the minute, you have it on the .click:

$('button').click(function(){
    $('div').animate({width:'400px'},300,function(){alert(0)})
            .promise()
            .done(function(){alert("1")});
})

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388416

You were calling the done on the button element, not on the div which is animated

$('button').click(function () {
    $('div').animate({
        width: '400px'
    }, 300, function () {
        alert(0)
    }).promise().done(function () {
        alert(1)
    })
})

Demo: Fiddle

Upvotes: 11

Related Questions