/html-dom /Basic
GitHub 5008★

Get the position of an element relative to the document

// Get the top, left coordinates of the element
const rect = ele.getBoundingClientRect();

// Add the scroll postion to get the full distance from the element
// to the top, left sides of the document
const top = rect.top + document.body.scrollTop;
const left = rect.left + document.body.scrollLeft;

See also

Follow me on and to get more useful contents.