Skip to content

Instantly share code, notes, and snippets.

@imikay
Created December 18, 2011 10:47
Show Gist options
  • Save imikay/1493009 to your computer and use it in GitHub Desktop.
Save imikay/1493009 to your computer and use it in GitHub Desktop.
Get an element's position using JS
function getElementPosition(element)
{
var x = element.offsetLeft;
var y = element.offsetTop;
var parent = element;
while (parent = parent.offsetParent)
{
x += parent.offsetLeft;
y += parent.offsetTop;
}
return [x, y];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment