Using javascript to find the position of DOM elements

I want to check the spatial organization of elements on a web page.

Can I get some sample code and pointers to resources.

Thanks.

+1
javascript webpage
source share
3 answers

If you need good modular code that you can read and easily extract only the bits you need, try David Mark MyLibrary (which you use to create your library).

I find that libraries like jQuery are so complex in themselves and depend on their own functionality that trying to track all functions and reassigning properties is an exercise in frustration. MyLibrary , on the other hand, is written very modular from the start and provides the best cross-browser capabilities.

0
source share

Here you go:

function position( elem ) { var left = 0, top = 0; do { left += elem.offsetLeft; top += elem.offsetTop; } while ( elem = elem.offsetParent ); return [ left, top ]; } 

Live demo: http://jsfiddle.net/dDyZF/2/

+3
source share

You have not requested jQuery, but you can check the jQuery dimensions plugin.

0
source share

All Articles