Skip to main content

Bug Tracker

Side navigation

#2737 closed enhancement (fixed)

Opened April 23, 2008 07:33AM UTC

Closed June 18, 2010 02:51AM UTC

calling css() with null parameter

Reported by: telega Owned by:
Priority: minor Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:
Description

Currently executing

 jQuery("#myid").css("top", top)
                .css("left", left)
                .etc...

with top = null is equivalent to executing css("top") without parameter. Thus an integer value is returned from css("top", top) call instead of "this". Thus executing of the consecutive operation css("left", left) results in an error.

I guess it would be more convenient to return this in case of css("xxx", null) calls.

I achieved this by adding

		if (arguments.length > 1 && value == undefined) return this;

line to the css() method. Though I'm not sure that this is the best solution as I'm not very well familiar with jQuery internals.

	css: function( key, value ) {
		// ignore negative width and height values
		if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
			value = undefined;

		if (arguments.length > 1 && value == undefined) return this;
		return this.attr( key, value, "curCSS" );
	},

Regards,

telega

Attachments (0)
Change History (3)

Changed April 23, 2008 04:23PM UTC by flesler comment:1

#2548 deals with this problem, the arguments.length approach could be implemented in it instead.

Changed December 26, 2008 08:08AM UTC by x-yuri comment:2

Also, if value is returned by some function

#!js
jQuery("#myid").css("top", top() )

we don't need to place value in separate variable, check if it's not null and then call jQuery("#myid").css(...)

#!js
var top = top();
if( top != null )
    jQuery("#myid").css("top", top )

Actually I can give even more examples

Changed June 18, 2010 02:51AM UTC by dmethvin comment:3

resolution: → fixed
status: newclosed

Fixed in 1.4.