jquery issue (bug?) in IE with .css() manipulation
<p>I have a block of jquery / javascript code that sets the left margin of an image depending on the browser width.</p>

<p>I do some sums to calculate the required left margin and it goes in var $diff.</p>

<p>This code works fine:</p>

<pre><code>$('#background-wrapper&gt;img').attr('alt',$diff);
</code></pre>

<p>which demonstrates that the sums are all working fine as the image ends up with the correct value for $diff inserted in its alt attribute. This works on IE, FF, Chrome.</p>

<p>But if I change the code to:</p>

<pre><code>    $('#background-wrapper&gt;img').css('margin-left',$diff);
</code></pre>

<p>then firefox and chrome work fine, using $diff as a value for the images left-margin as I intended, but IE throws a run time error and stops running the script, citing an Invalid Argument in jquery file. I'm using jquery 1.3.2.min.</p>

<p>Any ideas?</p>

<p>Heres the code for the full function. </p>

<pre><code>function imageResizeCenter() {
  var $windowh = jQuery(window).height();
  var $windoww = jQuery(window).width();

  var imagesrc = $('#background-wrapper2&gt;img').attr('src');

  var myimage = new Image();

  myimage.src = imagesrc;
  var $width = myimage.width;
  var $height = myimage.height;

  var $ratio = parseInt($width,10)/parseInt($height,10);

  var $newwidth = parseInt($windowh,10)*$ratio;

  var $diff = (parseInt($windoww,10)-parseInt($newwidth,10))/2;
  if($diff&lt;0) $diff=0;
  $('#background-wrapper2&gt;img').attr('height',$windowh).css('margin-left',$diff);

}
</code></pre>
