11

With jQuery how do i find out if div one is over div two? Not, which z-index is higher but what div is visually over the other div.

<style type='text/css'>
    #one {
    position:absolute; top:0; left:0; width:100px; height:100px; background-color:red; z-index:2;
    }
    #two {
    position:absolute; top:0; left:0; width:100px; height:100px; background-color:green; z-index:1;
    }
    </style>    
    <div id='one'></div>
        <div id='two'></div>
user892134
  • 3,078
  • 16
  • 62
  • 128
  • This might be a duplicate: http://stackoverflow.com/questions/8628368/how-do-i-implement-collision-detection-between-a-set-of-div-elements – Anderson Green Dec 29 '12 at 05:30

1 Answers1

14

You can use the offset method (here) to get the space from the document edges. Add the width and height of the elements, and substract the numbers.

Offset and width for div's

Lg102
  • 4,733
  • 3
  • 38
  • 61