tags:

views:

40

answers:

2

How would you get the position of a div?

Here is what i got so far

 <script> 
 $(document).ready(function() { 
 $("#draggable").draggable({ grid: [50, 20] }); 
 }); 
 </script> 
 <div id="drag_border"> 
 <div id="draggable" style="width:500; height:800">Drag me</div> 
 </div> 

Thank you

+3  A: 

Take a look at the .position() method.

Ken Redler
+5  A: 

In any of the events you can use ui.position, for example:

$("#draggable").draggable({ 
  grid: [50, 20],
  drag: function(e, ui) {
    var top = ui.position.top;
    var left = ui.position.left;
  }
}); 

You can give it a try here

Nick Craver
@Nick - Just curious. How'd you get the custom URLs on jsFiddle?
Peter Ajtai
@Peter - When you create a fiddle when logged in, that's how it generates the links when you fork
Nick Craver
@Nick - Thanks for the response. For some reason it isn't doing that for me when logged in using OpenId... I'll see if I can figure it out. Are you an alpha tester?
Peter Ajtai
@Peter - They have to make your account manually at the moment....public accounts will be there in beta :) OpenID is for SO, jsFiddle is a totally separate thing :)
Nick Craver