Skip to main content

Bug Tracker

Side navigation

#1388 closed bug (worksforme)

Opened July 11, 2007 11:04PM UTC

Closed November 17, 2007 04:48AM UTC

Last modified March 15, 2012 04:20PM UTC

.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:
Blocked by: Blocking:


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 packed.

Attachments (0)
Change History (3)

Changed July 14, 2007 04:32AM UTC by sgbeal comment:1

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).

Changed July 29, 2007 07:10PM UTC by john comment:2

component: ajaxcore

Changed November 17, 2007 04:48AM UTC by davidserduke comment:3

resolution: → worksforme
status: newclosed

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.