rupper = /([A-Z]|^ms)/g,
rnumpx = /^-?\d+(?:px)?$/i,
rnum = /^-?\d/,
- rrelNum = /^[+\-]=/,
- rrelNumFilter = /[^+\-\.\de]+/g,
+ rrelNum = /^([+\-])=([+\-\.\de]+)/,
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssWidth = [ "Left", "Right" ],
if ( value !== undefined ) {
type = typeof value;
- // Make sure that NaN and null values aren't set. See: #7116
- if ( type === "number" && isNaN( value ) || value == null ) {
- return;
- }
-
// convert relative number strings (+= or -=) to relative numbers. #7345
- if ( type === "string" && rrelNum.test( value ) ) {
- value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) );
+ if ( type === "string" && (ret = rrelNum.exec( value )) ) {
+ value = (ret[1] === "+"? +ret[2] : -ret[2]) + parseFloat( jQuery.css( elem, name ) );
// Fixes bug #9237
type = "number";
}
+ // Make sure that NaN and null values aren't set. See: #7116
+ if ( type === "number" && isNaN( value ) || value == null ) {
+ return;
+ }
+
// If a number was passed in, add 'px' to the (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";
});
test("css() explicit and relative values", function() {
- expect(27);
+ expect(29);
var $elem = jQuery("#nothiddendiv");
$elem.css({ width: 1, height: 1, paddingLeft: "1px", opacity: 1 });
$elem.css( "width", "-=9px" );
equals( $elem.width(), 1, "'-=9px' on width (params)" );
+ $elem.css( "width", "-=-9px" );
+ equals( $elem.width(), 10, "'-=-9px' on width (params)" );
+
+ $elem.css( "width", "+=-9px" );
+ equals( $elem.width(), 1, "'+=-9px' on width (params)" );
+
$elem.css({ paddingLeft: "+=4" });
equals( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );