javascript get element position relative to document

JavaScript
element.getBoundingClientRect().top + document.documentElement.scrollTop
Source

Also in JavaScript: