]> source.dussan.org Git - jquery.git/commitdiff
First proposed solution for IE6/7 get/setAttribute quirks. Needs more testing, but...
authortimmywil <tim.willison@thisismedium.com>
Fri, 11 Mar 2011 19:51:57 +0000 (14:51 -0500)
committertimmywil <tim.willison@thisismedium.com>
Sun, 3 Apr 2011 23:13:38 +0000 (19:13 -0400)
src/attributes.js
src/support.js

index 83d02e21221e356e75e877879934d83eb2c9d4a5..ee4dc1bad9686f622ae31f2497c4faaddc08ef64 100644 (file)
@@ -275,12 +275,6 @@ jQuery.extend({
                offset: true
        },
        
-       // TODO: Check to see if any of these are needed anymore?
-       // If not, it may be good to standardize on all-lowercase names instead
-       attrFix: {
-               
-       },
-
        attr: function( elem, name, value, pass ) {
                
                // don't get/set attributes on text, comment and attribute nodes
@@ -342,7 +336,7 @@ jQuery.extend({
                                // Look for the name in elem.attributes.name
                                var attrs = elem.attributes, i = 0, len = attrs.length;
                                for ( ; i < len; i++ ) {
-                                       if ( attrs[i]["name"] === name ) {
+                                       if ( attrs[i].name === name ) {
                                                return true;
                                        }
                                }
@@ -455,7 +449,7 @@ if ( !jQuery.support.style ) {
 // Safari mis-reports the default selected property of an option
 // Accessing the parent's selectedIndex property fixes it
 if ( !jQuery.support.optSelected ) {
-       
+
        jQuery.propHooks.selected = {
                get: function( elem ) {
                        var parent = elem.parentNode;
@@ -475,4 +469,31 @@ if ( !jQuery.support.optSelected ) {
        };
 }
 
-})( jQuery );
+// IE6/7 do not support getting/setting some attributes with get/setAttribute
+
+if ( jQuery.support.attrFix ) {
+       var attrFix = {
+               "for": "htmlFor",
+               "class": "className",
+               readonly: "readOnly",
+               maxlength: "maxLength",
+               cellspacing: "cellSpacing",
+               rowspan: "rowSpan",
+               colspan: "colSpan",
+               tabindex: "tabIndex",
+               usemap: "useMap",
+               frameborder: "frameBorder"
+       };
+       
+       jQuery.each(attrFix, function( key, name ) {
+               jQuery.attrHooks[ key ] = jQuery.extend( jQuery.attrHooks[ key ], {
+                       get: function( elem ) {
+                               return elem.getAttribute( name );
+                       },
+                       set: function( elem, value ) {
+                               elem.setAttribute( name, value );
+                               return value;
+                       }
+               });
+       });
+}
\ No newline at end of file
index 4c309562f7c17c6a7d17ebfd1c2a5a24af514c5b..3ca28d204f69c37b53ab5c1c37d133bf3c3f42c5 100644 (file)
@@ -7,8 +7,9 @@
        var div = document.createElement("div");
 
        div.style.display = "none";
+       div.setAttribute("className", "t");
        div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
-
+       
        var all = div.getElementsByTagName("*"),
                a = div.getElementsByTagName("a")[0],
                select = document.createElement("select"),
@@ -58,6 +59,8 @@
                // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
                optSelected: opt.selected,
 
+               attrFix: div.getAttribute("className") === "t",
+
                // Will be defined later
                deleteExpando: true,
                optDisabled: false,