function pos(elem) { var x = elem.offsetLeft, y = elem.offsetTop; while (elem = elem.offsetParent) { x += elem.offsetLeft; y += elem.offsetTop; } return [x, y];}