This worked for me (modified from highest voted answer):
function getOffset(el) {
const rect = el.getBoundingClientRect();
return {
left: rect.left + window.scrollX,
top: rect.top + window.scrollY
};
}
Using this we can call
getOffset(element).left
or
getOffset(element).top