javascriptpositionoffsetzepto

Get position/offset of element relative to a parent container?


How can I retrieve the offset of a container relative to a parent with pure JS?


Solution

  • element.offsetLeft and element.offsetTop give an element's position with respect to its offsetParent (which is the nearest parent element with a position of relative or absolute.)