Mosijava
Mosijava

Reputation: 4169

find position of an element relative to latest relative positioned parent with javascript

Is There any way to find an element position related to latest relative position parent?

I want a javascript way

assume we have this HTML

<div id="div1" style="position:relative"> 
   <div id="div2" style="padding:10px">
      <div id="div3" style="position:absolute top:15px; left:20px;">Stack</div>
   </div>
</div>

I want position of "div3" related to "div1".

Thanks

Upvotes: 7

Views: 3704

Answers (1)

Alex
Alex

Reputation: 35409

div3.offsetTop and div3.offsetLeft should fit your requirement(s).

Upvotes: 7

Related Questions