Home:ALL Converter>How to get position().left/top of an element before setting it to absolute position?

How to get position().left/top of an element before setting it to absolute position?

Ask Time:2013-09-21T00:18:04         Author:Geo C.

Json Formatter

I need to get the current position(top, left) of an element before I set it to absolute position .

doing this :

var left = $(element).position().left;
$(element).css({'position':'absolute'});  

left will allways be 0 . But the initial position is not 0 . If i don't use the css() method to set absolute position , left is returning the right left position . Any ideea about how to resolve this issue ?

P.S. : Before answerng , this bug was also posted on jquery bug tracker. But noone answered there neither . Read carefully my question . I'm not asking how to get the position , I'm asking why do I get the same position for any set of elements Jquery bug link. It's normal to get same position for all elements after you set them to absolute , not before . Or am I wrong ?

Author:Geo C.,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18921360/how-to-get-position-left-top-of-an-element-before-setting-it-to-absolute-posit
Overcode :

If you're trying to get it's css defined left position, use\n\nvar left = parseInt($element.css(\"left\"));\n\n\nIf you're trying to get it's position relative to the document, use\n\nvar left = $element.offset().left;\n",
2013-09-20T16:20:51
yy