jQuery: The Write Less, Do More JavaScript Library

Ticket #2737 (new enhancement)

Opened 4 months ago

Last modified 4 months ago

calling css() with null parameter

Reported by: telega Assigned to: anonymous
Type: enhancement Priority: minor
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords:
Cc: Needs: Review

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

Change History

Changed 4 months ago by flesler

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

Note: See TracTickets for help on using tickets.