I want to determine #target
's offset relative to #a
in the following HTML document – i.e., I want to find the values of x
and y
:
http://dl.dropbox.com/u/2792776/screenshots/2012-06-09_1814.png
jQuery has position()
, but $("#target").position()
returns #target
's offset relative to its offset parent, which is #c
(not #a
)
I need a function that's equivalent to $.fn.position()
, but instead returns the position relative to an "offset ancestor" of the target, rather than its direct offset parent. For example: $("#target").positionRelativeTo("#a")
You can calculate it based on offset:
var topoffset = $('#target').offset().top - $('#a').offset().top;
var leftoffset = $('#target').offset().left - $('#a').offset().left;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With