I have a straightforward inquiry: How can one determine the offsetTop
of a child element in relation to its parent element rather than the top of the window?
The definition of offsetTop
indicates that it should give the distance by which a child element is offset from the top of an offsetParent
, but this does not appear to be the case in the following JSFiddle example: http://jsfiddle.net/h5KBK/.
My objective is to ascertain the offset of the highlighted orange text from the top of the scrollable div, instead of measuring from the top of the window. Is there a way to achieve this without having to calculate the heights of preceding elements, paddings, margins, etc., and subsequently subtracting them from the offsetTop
value?
I am seeking a solution using only JavaScript. Please refrain from using jQuery.