jQuery, IE6 and the Display Property
This is a note to myself and anyone else encountering the following JavaScript error in IE6.
Could not get display property. Invalid argument.
This error applies specifically to jQuery when using the animate method. The animate method works only in steps, so you can’t toss in CSS commands sloppily (although other browsers will treat this okay). Instead, you have to specify the CSS separately.
In other words, your original function may look like this:
$("#myObject").animate({
display : 'block',
top: '+=10px'
});
But for it to work in IE6, you’ll need to revise it to the more verbose:
$("#myObject").css({
display: 'block'
}).animate({
top: '+=10px'
});
In some cases, you may get the old JavaScript error that IE throws whenever it gets confused:
Object doesn't support this property or method.
Always be careful not to use the animate method as short-hand for the css method, as doing so may cause IE6 to simply destroy all of your associated/caller functions and report that they don’t exist. There’s not really any simple way to debug this error, either, so just check for it whenever you can’t figure out what’s wrong.
hi mate,
thanks a lot for this post. it was also helpful with IE8 :)
July 14th, 2010 at 3:37 am
Glad to be of service, stranger. ;-)
July 14th, 2010 at 5:12 am