views:

44

answers:

3

I am using Jquery to apply some top and left positioning.

When doing so, in IE it works perfectly. Unfortunately, it doesn't work in Firefox or Chrome.

In IE, when inspecting the code it shows inline styles on the div for the left and top. When looking at chrome and firefox, there are no inline styles for the divs's.

Here is some code:

var offsets = $("#cssOffsets").val();           
var offsetsArray;  
offsetsArray = offsets.split(":");  
$('#lid').css({'top':offsetsArray[1],'left':offsetsArray[0]});

cssOffsets is a string like 137:10

The #lid div exists.

Any ideas on why it would actually work in IE and not the others?

I am using the latest version of Chrome and FireFox, and of JQuery.

Thanks!

+2  A: 

Just a guess, I think you need to specify the unit: px for example. So, when you fix that, you get:

$('#lid').css({
  top: offsetsArray[1] + "px",
  left: offsetsArray[0] + "px"
});
Harmen
A: 

hi, try this

$('#lid').offset({ top: offsetsArray[1], left: offsetsArray[0] });

The .offset() setter method allows us to reposition an element.

André Gadonski
A warning to users of .offset() - It sets the position according to the window and not the parent. To position according to the parent use .position().
Byron Cobb
+2  A: 

I think its because you're not specifying the px value.

$('#lid').css({'top':offsetsArray[1]+'px','left':offsetsArray[0]+'px'});
Byron Cobb