X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcss.js;h=f2165f904c05b8afbda90992846f16d3661cfe28;hb=e4a38670b10b1ce776afff389bae34991e986180;hp=8751860a8294843c6a48b77a3753eed17695274d;hpb=0229b83f7e5bf64edb2888ab349bedcd1a45e7c1;p=jquery.git diff --git a/src/css.js b/src/css.js index 8751860..f2165f9 100644 --- a/src/css.js +++ b/src/css.js @@ -70,7 +70,7 @@ jQuery.extend({ style: function( elem, name, value, extra ) { // Don't set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { - return undefined; + return; } // Make sure that we're working with the right name @@ -81,6 +81,11 @@ jQuery.extend({ // Check if we're setting a value if ( value !== undefined ) { + // Make sure that NaN and null values aren't set. See: #7116 + if ( typeof value === "number" && isNaN( value ) || value == null ) { + return; + } + // If a number was passed in, add 'px' to the (except for certain CSS properties) if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) { value += "px"; @@ -88,7 +93,11 @@ jQuery.extend({ // If a hook was provided, use that value, otherwise just set the specified value if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) { - style[ name ] = value; + // Wrapped to prevent IE from throwing errors when 'invalid' values are provided + // Fixes bug #5509 + try { + style[ name ] = value; + } catch(e) {} } } else { @@ -160,6 +169,10 @@ jQuery.each(["height", "width"], function( i, name ) { }); } + if ( val < 0 || val === 0 && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + return elem.style[ name ] || "0px"; + } + return val + "px"; } }, @@ -221,6 +234,9 @@ if ( getComputedStyle ) { if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) { ret = computedStyle.getPropertyValue( name ); + if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + ret = jQuery.style( elem, name ); + } } return ret;