Bug Tracker

Opened 14 years ago

Closed 13 years ago

Last modified 11 years ago

#4358 closed bug (invalid)

curCSS function in IE: "invalid argument"

Reported by: sdyson Owned by:
Priority: major Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:


The "curCSS" function has a special case for IE that uses "element.currentStyle". It sets a value on "style.left" and then retrieves the value as a way to convert to pixels. This works well most of the time but blows up for fields with multiple values. For example it is valid for "padding" to have a value of "0px 2px". In such a case you get an "invalid argument" error on line 835: "style.left = ret

This block of code seems to have originated from a fix by Dean Edwards at: http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291

Attachments (1)

curCSSTestCase.zip (37.5 KB) - added by carmine 14 years ago.
Test case showing the bug under IE7

Download all attachments as: .zip

Change History (10)

comment:1 Changed 14 years ago by carmine

I have the same issue with a margin.

It seems that replacing all the .left in the function with [name] fixes the bug.

I'll try to build a test case.

Changed 14 years ago by carmine

Attachment: curCSSTestCase.zip added

Test case showing the bug under IE7

comment:2 Changed 14 years ago by carmine

I just added a use case to the ticket. It can also be seen at http://www.novactive.com/2009-03-curcss/index.htm.

Please note that I use the selecteSizer plugin to trigger the bug.

I also added a patch in the page.

comment:3 Changed 14 years ago by sdyson

Thanks for the test case.

I'm not sure if your fix is correct according to the intention of the function. As I understand it the function will return a given css property but any non-px dimensions will get converted to px. Your function still uses pixelLeft for the return value so if I ask for "padding" which has an original value of "0px 2px" your function will return me "2px".

I think what might be needed is to split multi-value properties into the individual values, convert each in turn and then concatenate them together.

comment:4 Changed 14 years ago by sdyson

Actually, since padding is not related to left we don't know what pixelLeft will return.

comment:5 Changed 14 years ago by carmine

Yes, I just managed to prevent the error for IEs.

I thought that the error came from the use of .left that should be already defined for style.left, I did not get further (lack of time and knowledge).

comment:6 Changed 14 years ago by sdyson

The error happens because left expects a single dimension (e.g. 2px, 2%, 2em etc) but if the requested property is a multi-value one such as padding then the left property will fail to parse it.

Your solution is likely to have some very strange side-effects because you are returning a completely different property to the one that was originally asked.

comment:7 Changed 14 years ago by carmine

Oh, I did not understand that the code was only intending to get the left value... I do not understand why this value is so much more important than others...

comment:8 Changed 14 years ago by sdyson

The left property is being used because it has a corresponding pixelLeft property allowing conversion to pixels. The original left value is set back afterwards.

I may have some time tomorrow to have a go at fixing this.

comment:9 Changed 13 years ago by dmethvin

Resolution: invalid
Status: newclosed

The documentation for .css() is clear that shorthand properties are not supported for setting. The test case uses minified code so it's not very helpful for debugging. It appears that these bugs are in the plugins that cause the issue, not in jQuery, so please report them to the plugin authors.

Note: See TracTickets for help on using tickets.