dzumla011
dzumla011

Reputation: 612

Get updated position of the element

I have a div inside a parent div, and when I drag it and then click a button I want to show the left value of the element being dragged.

The way my code is now, it just reads it at the beginning of page load, but if I drag the div the position left does not update.

<div id="draggableHolder">
<div id="draggable"><p>drag me around</p></div>
</div>



$('#draggable').draggable({axis: 'x'});

var position = $('#draggable').position();

$('button').on('click', function() {
     console.log(position.left);
});

Basically now I always get 0, there is no update.

Upvotes: 1

Views: 40

Answers (1)

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try this -

console.log($('#draggable').position().left);

Upvotes: 1

Related Questions