Skip to main content Accessibility Feedback

Distances

getOffsetTop()

getOffsetTop() is a helper method I wrote to get an element’s distance from the top of the document.

var elem = document.querySelector('#some-element');
var distance = getOffsetTop(elem);

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.