Ticket #1388 (closed bug: worksforme)
.css('background-color',null) returns a String object
| Reported by: | sgbeal | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.1.4 |
| Component: | core | Version: | 1.1.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Hello!
The subject line says it all:
var v = $(foo).css('background-color',null); alert(v.toSource()); == (new String("transparent"))
!!!
i'm assuming that this is specific to background-color, and maybe other color-related CSS fields, but have not verified that.
The bug here is that the API docs say that the function returns a jQuery object, and here it returns a String object.
Using 1.1.3.1 packed.
Change History
comment:3 Changed 6 years ago by davidserduke
- Status changed from new to closed
- Resolution set to worksforme
I'm not aware of a case where undefined or null are valid css values. If someone can come up with such a case feel free to reopen the bug with the additional information.
This form of argument detection is common in jquery.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

It was explained to me on the list that the basic problem here is that css() assumes that a null/undefined as arguments[1] means that it should be invoked as a getter. A better solution for determine whether to call as a getter or setter is to use arguments.length instead of checking if arguments[1] is null/undefined. null is a valid value (at least for some fields) and undefined can easily be passed as a second argument by client-side code, e.g. css('foo',obj.missingAttributeHere).