Reputation: 12539
I have some draggable text and I would like to get it's coordinates within an element.
The text is made draggable through this code:
$("span.output").draggable({
stop: function(event, ui) {}
});
I also have this piece of code which is supposed to make the draggable text the child of the element the draggable text is in:
$('.container').on('drop', function(event, ui){
$(this).append(ui.draggable);
});
When I try $('#text1').position();
in console when the draggable text is within in the container, I get these coordinates:
Object {top: 57.11805772781372, left: 779.4444580078125}
Unfortunately, these are wrong. Is what I am trying to do even possible? If so, how can I do it?
Upvotes: 0
Views: 2803
Reputation: 655
This is the problem.
You are using
$('#text1').position();
It will give the postion relative to the container.
If you want the position relative to the document use this.
$('#text1').offset();
It has have $('#text1').offset().left
and $('text1').offset().right
It might help..
Upvotes: 1