Strontium_99
Strontium_99

Reputation: 1803

jquery position() not working in IE9

Has anybody else had problem with position() working odd in IE? I'm trying to return the left position of a div that is centrally placed. Chrome returns 342, which is right. IE9 returns 0.5. What's that all about?

  var sp = $('.jcarousel-container').position();
  alert(sp.left)

Upvotes: 3

Views: 6697

Answers (3)

Max Oriola
Max Oriola

Reputation: 1374

The only workaraund I came to work out was to do something like: var xpos_inside_parent = the_child.offset().left - the_parent.offset().left; It worked for me, yet I hope it'll be fixed soon in jquery.

$('#whatever').position() works in IE9 if set by CSS by numer (e.g 'left: 20px;'), but this is trivial to me, because if I set position by CSS, then it's already known and there's no need to retrieve it by jquery.

The following example shows that it doesn't work with a 'margin: 0 auto' centered element. It also shows my provisional fix substracting offsets: http://jsfiddle.net/maxoriola/MAwAH/4/

Upvotes: 2

Jeffrey
Jeffrey

Reputation: 2005

It seems that .offset() does work in IE9 in your jsfiddle example:

http://jsfiddle.net/fme6V/7/

Here's the code:

var sp = $('.jcarousel-container').offset();
alert(sp.left)

Upvotes: 7

Jeffrey
Jeffrey

Reputation: 2005

I've got it working using this code. Perhaps you can use it to correct your own.

http://jsfiddle.net/fme6V/

Upvotes: 0

Related Questions