To get the top/left coordinates of an element relative to its parent, you use the offsetLeft and offsetTop properties. The return values are in px:
const el = document.querySelector('.box');
console.log(el.offsetLeft, el.offsetTop);
Code language: JavaScript (javascript)
Was this tutorial helpful ?