Skip to content

Commit

Permalink
Attributes: Don't set the type attr hook at all outside of IE
Browse files Browse the repository at this point in the history
This removes a needless function call in modern browsers.

Closes gh-4587
  • Loading branch information
mgol committed Jan 13, 2020
1 parent 437f389 commit 9e66fe9
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/attributes/attr.js
Expand Up @@ -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,
Expand All @@ -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 ) {
Expand Down

0 comments on commit 9e66fe9

Please sign in to comment.