dzumla011
dzumla011

Reputation: 612

Get updated position of an element after click

After I click a button an element's left position is animated, I need to get that new position, not the starting position.

$('button').on('click', function() {
    $('div.move').animate({left: 300});
    var v = $('div.move').position().left;
    console.log(v); 
});

FIDDLE

Upvotes: 0

Views: 58

Answers (1)

karthikr
karthikr

Reputation: 99620

You need to get the value as a callback:

$('button').on('click', function () {
    $('div.move').animate({
        left: 300
    }, function () {
        var v = $('div.move').position().left;
        alert(v);
    });

});

Check this fiddle

Upvotes: 2

Related Questions