Sometimes, when I ask for the .position().top
value of some object, it does not return the absolute value, i.e. if some picture is added before, the .position().top
value does not change. How may I ask for the absolute position of an object (in this case a div)?
Asked
Active
Viewed 446 times
2

Jjm
- 261
- 2
- 10
-
1@PrakharSingh, if there's no top set in css that will return empty. – Mouser Feb 01 '15 at 11:50
-
1@PrakharSingh I only get 'auto' – Jjm Feb 01 '15 at 11:51
-
2Use `offset()` instead of `position()` – Mouser Feb 01 '15 at 11:52
-
1@Mouser Yes, right, it works!! – Jjm Feb 01 '15 at 11:54
-
1Too bad I didn't post it as an answer. Give Mario the reward :) – Mouser Feb 01 '15 at 11:55
-
@Mouser Sorry for that, I guess we had the same idea almost at the same time. – Mario A Feb 01 '15 at 12:16
-
I shouldn't have used a comment, so no sorry here. You deserve it. Got XP enough. – Mouser Feb 01 '15 at 12:17
1 Answers
2
From the jquery docs:
The .position() method allows us to retrieve the current position of an element relative to the offset parent. Contrast this with .offset(), which retrieves the current position relative to the document.
http://api.jquery.com/position/
So use .offset()
.

Mario A
- 3,286
- 1
- 17
- 22