Bug Tracker

Opened 15 years ago

Closed 13 years ago

#2737 closed enhancement (fixed)

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:


Currently executing

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

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

Change History (3)

comment:1 Changed 15 years ago by flesler

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

comment:2 Changed 14 years ago by x-yuri

Also, if value is returned by some function

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

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

Actually I can give even more examples

comment:3 Changed 13 years ago by dmethvin

Resolution: fixed
Status: newclosed

Fixed in 1.4.

Note: See TracTickets for help on using tickets.