2

this has baffled me for a couple of hours now. Why do i get a 'Invalid Argument' error when testing this in IE8?

function resizeContainer() {
    wHeight = window.innerHeight;
    $('.container').each(function () {
        $(this).animate({
            height: wHeight
        }, 400);
    });
    $('.content').each(function () {
        wHeight = window.innerHeight;
        fullPad = wHeight - $(this).height();
        if (wHeight < 750) {
            cropFactor = 1.7;
        }
        else {
            cropFactor = 2;
        }
        $(this).animate({
            paddingTop: fullPad / cropFactor
        });
    });
}

The exact error im getting is:

Invalid argument. jquery.js, line 8826 character 5

Esailija
  • 138,174
  • 23
  • 272
  • 326
Jonas Thomsen
  • 103
  • 3
  • 10
  • What is the jQuery version you are using? Is this the line `jQuery._data( self.elem, "fxshow" + self.prop, self.start );` ? – Esailija Jun 25 '12 at 12:35
  • I'm using jQuery 1.7 from here: http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js – Jonas Thomsen Jun 25 '12 at 12:36
  • So the line is this `fx.elem.style[ fx.prop ] = fx.now + fx.unit;` Where `element.style["paddingTop"]` is receiving invalid argument. – Esailija Jun 25 '12 at 12:37
  • 1
    try adding `+'px'` to paddiTop calc – charlietfl Jun 25 '12 at 12:38
  • I can reproduce this in IE8 with `document.createElement("div").style.paddingTop = NaN; //"Invalid argument."` Make sure that `fullPad/cropFactor` doesn't return `NaN` – Esailija Jun 25 '12 at 12:38
  • Yeah that's about right. But... why? And what is IE's problem. Sucky browser. – Jonas Thomsen Jun 25 '12 at 12:39
  • @charlietfl jQuery automatically adds `"px"`. – Rob W Jun 25 '12 at 12:43
  • ***ALWAYS*** use the `var` keyword when declaring variables. There is no situation where leaving off the var keyword is not wrong. With `var` you create function local variables, without `var` you create global variables. This can lead to some very "interesting" bugs, so don't do that. – Tomalak Jun 25 '12 at 12:45

1 Answers1

5

window.innerHeight is not defined prior IE, so wHeight is undefined, and fullPad becomes NaN. Try $(window).height() instead.

Setting invalid style values in IE is one of the causes of the "Invalid argument" error.

Rob W
  • 341,306
  • 83
  • 791
  • 678