Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#6524 closed bug (invalid)

ie8 and NaNpx value

Reported by: virgil.balibanu Owned by:
Priority: Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


sometimes it might happen that jquery receives a NaNpx value for a style, like top or left, and ie8 does not like that so it will raise a js error (Invalid Argument) on line 4618 (1.4.2 development version) style[ name ] = value; this could easily be fixed by either modifying the value to 0px by doing something like this value=(value=='NaNpx'?'0px':value); or by putting the assignment in a try catch block. Could you please do either of this, because it's very hard for the user to find where the NaNpx will appear from.

Change History (9)

comment:1 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

If your code is passing "NaNpx" to jQuery then it is passing in invalid arguments. You can easily tell which code is to blame by using the IE8 debugger (Press F12) and view the call stack at the point of the error.

comment:2 Changed 9 years ago by virgil.balibanu

Resolution: invalid
Status: closedreopened

well, only ie8 sees NaNpx as an error, ie7 and ff ignore it. And second I have my windows on a virtual machine so that I can test my site with ie, so the debugger is pretty useless. I had to download the jquery development version and print elem.id in a catch block to see where the exception was coming from. The error comes from jquery, as in a few methods in js i gave dimensions ending in 'px', like this: var top = document.documentElement.clientHeight + document.documentElement.scrollTop + 'px'; $('#wrraper_help_window').css({'top': top}); So i presume it is a jquery bug. Probably trying to parse the value as an integer directly and returning NaN then adding 'px' to it.

comment:3 Changed 9 years ago by dmethvin

Resolution: invalid
Status: reopenedclosed

I don't see any use of document.documentElement.scrollTop in jQuery itself. If you can provide a complete test case that demonstrates that the problem is internal to jQuery (that is, the "NaNpx" is coming from within jQuery and not your code) then attach the test case and reopen the ticket.

comment:4 Changed 9 years ago by marcdraco

Resolution: invalid
Status: closedreopened

I may be wrong here, but I have had a similar issue.

here is a snippet where the "target" is from the event object. I seemed to be getting NaNs from ParseINT which seems to suggest that IE is pulling a fast one on jQuery. The solution for me is to test for the NaN and 0 the value.

cssOffset.X = parseInt($(target).css("margin-left"),10); cssOffset.Y = parseInt($(target).css("margin-top"),10); cssOffset.X = (isNaN(cssOffset.X)) ? 0 : cssOffset.X; cssOffset.Y = (isNaN(cssOffset.Y)) ? 0 : cssOffset.Y;

It appears that IE8 returns "auto" for these values unless they are explicitly set - whereas (FF) presumably returns the computed style.

comment:5 Changed 9 years ago by dmethvin

Resolution: invalid
Status: reopenedclosed

No test case attached. Please do not reopen this ticket without a test case.

comment:6 Changed 9 years ago by readyman

Although this is probably not jquery's fault, there is no error handling in the offending line & all the debuggers I have used point to a line in the jquery code and not to any plugin scripts. I would have to basically rewrite the plugins to make this error go away. Not a good solution.

Here is the quick fix... Find the "offending" code in jquery code around line 4618 style[ name ] = value; replace with try{style[ name ] = value;} catch (error){};

If using the minified version Around line 116 change f[b]=d; to try{f[b]=d;}catch (error){};

comment:7 Changed 9 years ago by cmcculloh

Resolution: invalid
Status: closedreopened

I believe this is actually a result of passing an object with only one property to the offset function:

Steps to reproduce:

Run this code in IE 7 with script debugging ENABLED:

<!DOCTYPE html> <html> <head>

<style>p { margin-left:10px; } </style> <script src="http://code.jquery.com/jquery-latest.min.js"></script>

</head> <body>

<p>Hello</p><p>2nd Paragraph</p>

<script>$("p:last").offset({ top: 10 });</script> </body> </html>

Note that we only passed { top: 10 } to offset instead of { top: 10, left: 10 }.

Expected Result:

2nd paragraph moved to top 10px with no errors

Actual Result:

2nd paragraph moved to top 10px with "Invalid Argument" runtime errors being thrown

The problem is actually line 4618 of the un-minified jquery source 1.4.2:

style[ name ] = value;

"value" here is set to "NaNpx", which, while technically correct is sub-optimal. It seems there should be some error checking added:

if(value !== "NaN" && value !== "NaNpx"){

style[ name ] = value;


(or something more optimal, idk, this is my first bug ticket...)

Forking project, submitting patch: http://github.com/cmcculloh/jquery/commit/2bbffc5f84dfabfd45f80069838d42a3b4e6034e

comment:8 Changed 9 years ago by cmcculloh

Looks like this was already fixed in a much better way in commit 08cf82e88e7a1f88da34 by brandonaaron on 3/22/2010.

comment:9 Changed 9 years ago by dmethvin

Resolution: invalid
Status: reopenedclosed

Since we're lacking a test case lets just say that this was fixed by the 3/22 patch and it will be fixed in the next release. Since there's no test case it's not possible to know if it will really be fixed. If someone can come up with a test case that shows the patch fixed the problem I'll change the status of this bug to "fixed".

Note: See TracTickets for help on using tickets.