views:

19

answers:

1

in jquery/javascript I'm trying to find how far left an element is with position:relative. There are several elements between this one and the left of the screen. since it is positioned:relative and float:left using:

 $(this).css('left');

gives me '0px' every time. So how do I found how far the element is from the left of the screen?

+1  A: 

You can use jQuery's .offset() method.

Here's an example: http://jsfiddle.net/PgbmV/

$(this).offset().left;

This will give the left position relative to the document.

If you want the position relative to its container, you would use .position() in a similar manner.

$(this).position().left;
patrick dw
thanks greatly!!!!
sadmicrowave
@sadmicrowave - You're welcome. :o)
patrick dw