]> source.dussan.org Git - jquery.git/commitdiff
Attributes: Don't set the type attr hook at all outside of IE
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 13 Jan 2020 18:22:08 +0000 (19:22 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Jan 2020 18:22:08 +0000 (19:22 +0100)
This removes a needless function call in modern browsers.

Closes gh-4587

src/attributes/attr.js

index cd34860e1fa85b872678035fcdfb57217544bf32..2773a383c5bd1c6f0b2f290296e8639b0b0b45c7 100644 (file)
@@ -64,23 +64,7 @@ jQuery.extend( {
                return ret == null ? undefined : ret;
        },
 
-       attrHooks: {
-               type: {
-                       set: function( elem, value ) {
-
-                               // Support: IE <=11+
-                               // An input loses its value after becoming a radio
-                               if ( isIE && value === "radio" && nodeName( elem, "input" ) ) {
-                                       var val = elem.value;
-                                       elem.setAttribute( "type", value );
-                                       if ( val ) {
-                                               elem.value = val;
-                                       }
-                                       return value;
-                               }
-                       }
-               }
-       },
+       attrHooks: {},
 
        removeAttr: function( elem, value ) {
                var name,
@@ -98,6 +82,23 @@ jQuery.extend( {
        }
 } );
 
+// Support: IE <=11+
+// An input loses its value after becoming a radio
+if ( isIE ) {
+       jQuery.attrHooks.type = {
+               set: function( elem, value ) {
+                       if ( value === "radio" && nodeName( elem, "input" ) ) {
+                               var val = elem.value;
+                               elem.setAttribute( "type", value );
+                               if ( val ) {
+                                       elem.value = val;
+                               }
+                               return value;
+                       }
+               }
+       };
+}
+
 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) {
        jQuery.attrHooks[ name ] = {
                get: function( elem ) {