Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 8 years ago

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

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 (3)

comment:1 Changed 13 years ago by sgbeal

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

comment:2 Changed 13 years ago by john

Component: ajaxcore

comment:3 Changed 13 years ago by davidserduke

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.

Note: See TracTickets for help on using tickets.