So you have options. position () or offset () .
position () It basically looks like you could use the left properties in the top CSS layer.
offset () Returns the distance from the document. It considers margins, gaskets and borders.
<style> .cont { position: absolute; top: 100px; left: 100px; border: solid 3px black; } p { margin: 20px; padding: 20px; border: solid 2px black; position: absolute; top: 20px; left: 20px; } </style> <div class="cont"> <p>Hello World!</p> </div> $('p').position() => { top: 20, left: 20 } $('p').offset() => { top: 143, left : 143 }
Notice how the position values ββmatch the CSS values, and the offset considers the position of the parent, the border of the parent element and the field ('p'), and padding.
http://jsfiddle.net/4wfa6/
http://docs.jquery.com/CSS
guzart
source share