Take the 2-minute tour ×

When I'm trying to use jQuery like this: $('#myDiv').css('left')

In chrome it returns 10% which is what I expected because I set the left value as 10%;

But in firefox it returns value in px? How can I always get the 10%?


So I think to get same results from all browsers it's better to let it return offset values.

share|improve this question
Could you post your css? –  AbstractChaos Jun 16 '11 at 13:39
How do you set the left value? –  RoToRa Jun 16 '11 at 15:12
I set it as $('#myDiv').css('left', '10%') –  Jane Jun 16 '11 at 15:42
add comment

1 Answer

up vote 0 down vote accepted

I believe you can get a consistent response from...

var position = $('#myDiv').position();
var left = position.left;

This may not be in % as you want, but will be the same in all browsers. You might want offset() rather than position, if you want the position relative to the parent container.

share|improve this answer
I just checked Firebugs "Computed" styles. Same same, just shows the pixels. –  roberkules Jun 16 '11 at 14:05
add comment

Your Answer


