Full version: jsB@nk » Snippet » getPosition
URL: https://www.javascriptbank.com/getposition.html
When a layer is inside another layer, it's style.left and style.top positions can both be '0' but the layer itself can be 500 pixels away from the actual margin. These functions will return the true offset.
Full version: jsB@nk » Snippet » getPosition
URL: https://www.javascriptbank.com/getposition.html
<script type="text/javascript">// Created by: Ultimater :: http://ultimiacian.tripod.com/// Tested and Demo by Thái Cao Phong , http://javascriptbank.com// To find the left position, add this snippet to your code:function getPositionLeft(This){var el = This;var pL = 0;while(el){pL+=el.offsetLeft;el=el.offsetParent;}return pL}// To find the top position, add this snippet to your code:function getPositionTop(This){var el = This;var pT = 0;while(el){pT+=el.offsetTop;el=el.offsetParent;}return pT}window.onload=function(){alert(' Tested by JavaScriptBank.com \n' +'Left: '+getPositionLeft(document.getElementById('test')) +'\nTop: '+getPositionTop(document.getElementById('test')));}</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<div style="position: absolute; width: 444px; height: 36px; z-index: 1; left:258px; top:302px" id="test"></div><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->