Ticket #4420 (closed bug: invalid)
Internet Explorer 7 error: problem setting elem[ name ] = value
| Reported by: | erinnn | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.4 |
| Component: | attributes | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I found a minor problem in IE that does not happen with Firefox or Chrome.
On line 1002 and 1065 of jQuery JavaScript Library v1.3.2 "elem[ name ] = value;" will throw an error, if the value can not be set on the property. In my case, I found the error when I tried to assign NaN px from a calculation to the left property of an element. FIrefox and chrome continued, while IE my element did not display.
Putting this line in a try block with an empty catch allowed IE to fail more gracefully, like Chrome and Firefox did when given a bad value.
Change History
comment:2 Changed 4 years ago by erinnn
What I meant to highlight as the issue was inconsistent behavior in IE.
The NaN was just a bad input - when this code fails to set the value on a property the behavior in IE is inconsistent with (and worse than) what other browsers show. Making behavior more predictable across browsers is one of the highlights of jQuery.
The two other browsers failed gracefully, masking the underlying error. Doing so with the library in IE would help standardize javascript behavior across browsers in failure conditions.
comment:3 Changed 4 years ago by dcostalis
Changing
elem[ name ] = value
to
try{elem[ name ] = value} catch(err){};
on lines 1002 and 1065 not only gives consistent behavior, but allows the script to continue. IE7 halts under some conditions.
comment:4 Changed 4 years ago by dmethvin
The conditions where IE halts are ones where Firefox is ignoring code errors AFAICT. You'd want to figure out why you were passing NaN to jQuery.
comment:5 Changed 4 years ago by netinho
I had the same problem, and on IE8 too. So I solved using this way at line 1060 of jquery-1.3.2.js:
on:
if ( set ) elem[ name ] = value;
to:
if ( set ) {
if ((value == 'NaNpx')||(value == 'px')) value = '';
elem[ name ] = value;
}
Now it's working like a charm.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

It sounds like this would just mask the underlying error though. Where was the NaN} coming from?