Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  45] [ 2]  / answers: 1 / hits: 50283  / 12 Years ago, fri, march 1, 2013, 12:00:00

I have two DIVs that I need to know the calculated browser distance (in height) of them.
I have read about the offset feature but the examples were not written for the way I am trying to do this.



Example usage:



<div class=foo></div>
<div class=bar></div>


I want to know the distance between these two.



Please help me to find the distance dynamically with jQuery.


More From » jquery

 Answers
406

Something like this should work:



$('.foo').offset().top - $('.bar').offset().top


As long as each class only has one element on the page.

If they are not unique, give the two elements an ID and reference with that.


[#79916] Thursday, February 28, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominics

Total Points: 424
Total Questions: 99
Total Answers: 107

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
dominics questions
Wed, Apr 6, 22, 00:00, 2 Years ago
Thu, Jan 13, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
;