# JavaScript positioning question

**URL:** <https://boards.straightdope.com/t/javascript-positioning-question/338579>\
**Category:** Factual Questions\
**Created:** [January 5, 2006, 3:38pm UTC](https://boards.straightdope.com/t/javascript-positioning-question/338579 "2006-01-05T15:38:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlyingCowOfDoom](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/flyingcowofdoom/32/21776_2.png) [@FlyingCowOfDoom](https://boards.straightdope.com/u/FlyingCowOfDoom)\
**Post date:** [January 5, 2006, 3:38pm UTC](https://boards.straightdope.com/t/javascript-positioning-question/338579/1 "2006-01-05T15:38:41Z")

</div>

I want to get the left and top (relative to window) coordinates for an image I have on a page. The image is not absolutely positioned. Let’s say it is centered in a DIV. Is there any way to get the left and top values using JS?

TIA!

–FCOD

---

<div class="post-metadata">

**Author:** ![Omphaloskeptic](https://avatars.discourse-cdn.com/v4/letter/o/bcef8e/32.png) [@Omphaloskeptic](https://boards.straightdope.com/u/Omphaloskeptic)\
**Post date:** [January 5, 2006, 11:46pm UTC](https://boards.straightdope.com/t/javascript-positioning-question/338579/2 "2006-01-05T23:46:41Z")

</div>

> [@FlyingCowOfDoom](#):
>
> I want to get the left and top (relative to window) coordinates for an image I have on a page. The image is not absolutely positioned. Let’s say it is centered in a DIV. Is there any way to get the left and top values using JS?

In general I believe you have to recursively traverse the offsetParent references; see [here](http://www.quirksmode.org/js/findpos.html).
