plainJS

Functions / Styles

Get the offset position of an element relative to its parent

jQuery $.position()

2015 page

This is the original page from 2015, kept at its address while the tested rewrite is in progress. The code is of its time: it ran in Internet Explorer and does not use what browsers have gained since. The rewrite replaces it here.

In short

Get the top/left coordinates of an element relative to the offset parent.

Use offsetLeft and offsetTop for finding an element’s position in px with respect to its offsetParent container:

js
var el = document.querySelector('div');
console.log(el.offsetLeft, el.offsetTop);