This gives me the position of some element from the left edge of the main window:
$('#bar').offset().left;
If that element is situated inside some other element and I wanted the position of #bar relative to #foo (it's parent), how can I get that?
<style>
#foo { width: 200px; margin: 0 auto; }
#foo #bar { width: 50px; margin: 0 auto; }
</style>
<div id="foo">
<span id="bar"></span>
</div>
I saw that there is a function called offsetParent()
but when console logged it doesn't seem like this function has any properties called left
or x
. So not sure if that can be used to get what I need.
So in my example above the offset should be something around 125px from the parent's edge rather than some thousands of pixels from the main windows edge.