When trying to get the position of an element using jQuery's .offset()
, I then set the div to have a position:absolute;
and adjust its left
and top
based on the information obtained from offset()
.
This method works well when all the element's parents are statically positioned since position:absolute
is relative to its first positioned (not static) ancestor element.
Now, I am faced with two options to address this issue:
- Find a way to force the element to be positioned relative to the document. I haven't found any CSS specification that allows for this yet.
- Instead of relying on
offset()
, utilize a function that captures the element's position in relation to its first positioned ancestor element. While there isn't a specific jQuery function for this,position()
can provide positioning relative to the element's parent.
How can I implement either of these two solutions successfully?