diff options
author | timmywil <tim.willison@thisismedium.com> | 2011-04-03 18:18:32 -0400 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-04-03 19:13:41 -0400 |
commit | ad2b3bc9f908a8e529c4479c8c9baead23c2d827 (patch) | |
tree | a5bcf0f8f782983daaeaeeb3891f6752742278f6 /src/attributes.js | |
parent | 2a8a2b61488e7857b116bedc9eb75bd971772c2f (diff) | |
download | jquery-ad2b3bc9f908a8e529c4479c8c9baead23c2d827.tar.gz jquery-ad2b3bc9f908a8e529c4479c8c9baead23c2d827.zip |
Found a problem removing the style attribute in IE
- Style is now a special case in IE6/7 to set cssText. My goal is to avoid calling attr again for the performance benefit, and at this point it would also cause an infinite loop for the boolean attributes hooks such as selected & checked. Nevertheless, style seems to be the only one requiring a special call.
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/attributes.js b/src/attributes.js index b472e617c..ced9977e4 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -276,7 +276,8 @@ jQuery.extend({ attrFix: { // Always normalize to ensure hook usage - tabindex: "tabIndex" + tabindex: "tabIndex", + readonly: "readOnly" }, attr: function( elem, name, value, pass ) { @@ -339,10 +340,14 @@ jQuery.extend({ if ( jQuery.support.getSetAttribute ) { elem.removeAttribute( name ); } else { - // Set to default empty string (No longer need to use attr for this) - elem.setAttribute( name, "" ); - // Attempt to remove completely with DOM level 1 - elem.removeAttributeNode( elem.getAttributeNode( name ) ); + // Only style is a special case. + if ( name === "style" ) { + elem.style.cssText = ""; + } else { + elem.setAttribute( name, "" ); + // Attempt to remove completely with DOM level 1 + elem.removeAttributeNode( elem.getAttributeNode( name ) ); + } } } }, @@ -415,7 +420,6 @@ if ( !jQuery.support.getSetAttribute ) { jQuery.attrFix = jQuery.extend( jQuery.attrFix, { "for": "htmlFor", "class": "className", - readonly: "readOnly", maxlength: "maxLength", cellspacing: "cellSpacing", rowspan: "rowSpan", @@ -447,12 +451,10 @@ if ( !jQuery.support.getSetAttribute ) { } // Remove certain attrs if set to false -jQuery.each([ "selected", "checked", "readonly", "disabled" ], function( i, name ) { - name = jQuery.attrFix[ name ] || name; - +jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { set: function( elem, value ) { - if ( !value ) { // '', undefined, false, null will remove attr + if ( !value ) { jQuery.removeAttr( elem, name ); return false; } @@ -472,9 +474,10 @@ if ( !jQuery.support.hrefNormalized ) { } if ( !jQuery.support.style ) { - jQuery.propHooks.style = jQuery.attrHooks.style = { + jQuery.attrHooks.style = { get: function( elem ) { - return elem.style.cssText; + // Return undefined in the case of empty string + return elem.style.cssText || undefined; }, set: function( elem, value ) { return (elem.style.cssText = "" + value); |