views:

558

answers:

1

I have a droppable container with >1 draggables in it. I want to simply be able to see the position of each draggable every time any one of them is dragged. Sounds easy, but I'm having a tough time figuring it out. Here's what I have:

<script type="text/javascript">
$(function() {
 $("#draggable").draggable({ containment: '#droppable' });
 $("#draggable2").draggable({ containment: '#droppable' });
 $("#droppable").droppable({
  drop: function(event, ui) {
   document.getElementById('position1').value = ui.position.top + ', ' + ui.position.left; 
  }
 });

});
</script>

Basically, where I have the position1 input id gathering the position, I want to have a second line do the same thing for the other draggable.

A: 

In your case, you don't need to use the ui parameter. Since you know what elements are draggable, you can select them specifically and find their positions. Also, since you're using jQuery, do yourself a favor and replace document.getElementById with $. :-)

No Surprises
Thanks for helping me get in the right direction! Seems like I know what should be possible, just don't know the syntax or how to get there. I tried selection the draggable to get their positions, but wasn't getting anything until I did .position() rather than .position. Thanks! :)