.position() returns an offset from the static element on IE and Edge
Author: YojiBCreated May 22, 2019Updated May 4, 2026
LabelsOffset
The following code is an implementation of .position() from jquery-3.4.1.js.
// Account for the *real* offset parent, which can be the document or its root element
// when a statically positioned element is identified
doc = elem.ownerDocument;
offsetParent = elem.offsetParent || doc.documentElement;
while ( offsetParent &&
( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
jQuery.css( offsetParent, "position" ) === "static" ) {
offsetParent = offsetParent.parentNode;
}
Does the .position() need the parent of root only ?
I do not think so.
If so, the code should be "if" and not "while".
( offsetParent === doc.body || offsetParent === doc.documentElement )
is not repeat condition, it is break condition I think.
In IE and Edge, if the target element in the table, the .position() returns offset from the table-cell (it's IE and Edge's offsetParent).
I guess the code is intended to be:
!( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
Note by @mgol: I edited the post to add code formatting. (2019-07-01)
Source: jquery/jquery