X10nD
X10nD

Reputation: 22040

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 Jean

Upvotes: 18

Views: 38147

Answers (2)

Orbling
Orbling

Reputation: 20612

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.

Upvotes: 27

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103145

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;

Upvotes: 7

Related Questions