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?
You can use jQuery’s
.offset()method.Here’s an example: http://jsfiddle.net/PgbmV/
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.