get div left and right value using jquery
There is no left assigned for the div, I use $('#').css('left');
to get the left value, but it shows auto.
How do I get the left value of the div.
Thanks Je开发者_如何转开发an
The .css() command returns what the CSS setting is, so if you have 'auto' set, that is what you will see.
You can retrieve the computed position relative to the parent with $('#').position().left;
, 'top' also is available from position(), if you want the value relative to the document use $('#').offset().left
.
The offset() method tells you the actual position of the element relative to the document. See the example on the page that I linked to to see how they got the left and top values.
That is:
var left = $('Your_selector').offset().left;
精彩评论