jQuery.each( [ "height", "width" ], function(i,n){
jQuery.fn[ n ] = function(h) {
return h || h===0?
this.css( n, isNaN(h)? h : h + "px" ):
( this.length ? jQuery.css( this[0], n ) : null );
};
});
The (h
h===0) checking works right with undefined, null and NaN values. The original checking was h==undefined. Example the IE doesn't work correct with NaN value.
And if the h parameter is a string, but doesn't closed with "px" string, then isNaN checking is right.
Attachments
Change History
Download in other formats:
|