#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: | ||
Blocked by: | Blocking: |
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 (6)
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
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 14 years ago by
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 14 years ago by
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 13 years ago by
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.
comment:6 Changed 13 years ago by
Component: | unfiled → attributes |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Closing the ticket, no test case showing a bug. The string "NaN" for .attr or .css is not valid input, so code should not be passing this to jQuery.
It sounds like this would just mask the underlying error though. Where was the
NaN
} coming from?