Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  145] [ 1]  / answers: 1 / hits: 17100  / 14 Years ago, wed, august 25, 2010, 12:00:00

This question is quite similar to what I want I'm looking for, but my situation is different enough, I think, to merit a new question.



I have several divs positioned absolutely inside of a parent div (position: relative). I want to get the position of the children divs relative to the window. The jquery offset() method doesn't seem to work, because it gives me the offset from the parent div. Is there a way to get the absolute position of a div that has absolute position inside of a relative position div?



Sample html:



<div id=parent style=position:relative;>
<div id=child1 style=position:absolute; top:10px; left 8px;>Child 1</div>
<div id=child2 style=position:absolute; top:20px; left 8px;>Child 2</div>
</div>

More From » jquery

 Answers
13

There's the .position() function too, however (though they're perpetually confusing to me) my understanding is backwards from what you've written: .offset() is relative to the document origin, while .position() is relative to the offset parent.



I think it's the fact that the term offset parent contains the word offset that confuses me.


[#95807] Tuesday, August 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadap

Total Points: 101
Total Questions: 104
Total Answers: 98

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;