Repository: jquery/jquery
File: src/attributes/attr.js (JavaScript)

Code before:
// 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( (
	"checked selected async autofocus autoplay controls defer disabled " +
	"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {
	jQuery.attrHooks[ name ] = {
		get: function( elem ) {
			var ret,
				isXML = jQuery.isXMLDoc( elem ),
				lowercaseName = name.toLowerCase();

			if ( !isXML ) {
				ret = elem.getAttribute( name ) != null ?
					lowercaseName :
					null;
			}
			return ret;
		},

		set: function( elem, value, name ) {
			if ( value === false ) {

				// Remove boolean attributes when set to false
				jQuery.removeAttr( elem, name );
			} else {
				elem.setAttribute( name, name );
			}
			return name;
		}
	};
} );


Review comment (suggestion):
```suggestion
// HTML boolean attributes have special behavior:
// we consider the lowercase name to be the only valid value, so
// getting (if the attribute is present) normalizes to that, as does
// setting to any non-`false` value (and setting to `false` removes the attribute).
// See https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
jQuery.each( (
	"checked selected async autofocus autoplay controls defer disabled " +
	"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {
```

Note also that our list is outdated; it is missing several boolean attributes from [HTML Attributes](https://html.spec.whatwg.org/multipage/indices.html#attributes-3), includes a `scoped` that isn't even present there, and treats [`hidden`](https://html.spec.whatwg.org/multipage/interaction.html#the-hidden-attribute) as boolean despite the expansion of that attribute to be an enumeration including "until-found" by https://github.com/whatwg/html/commit/f5def65bda4d01a6a1e105fcf13fe45201b4f48a .

Code after:
// 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;
			}
		}
	};
}

// HTML boolean attributes have special behavior:
// we consider the lowercase name to be the only valid value, so
// getting (if the attribute is present) normalizes to that, as does
// setting to any non-`false` value (and setting to `false` removes the attribute).
// See https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
jQuery.each( (
	"checked selected async autofocus autoplay controls defer disabled " +
	"hidden ismap loop multiple open readonly required scoped"
).split( " " ), function( _i, name ) {
	jQuery.attrHooks[ name ] = {
		get: function( elem ) {
			var ret,
				isXML = jQuery.isXMLDoc( elem ),
				lowercaseName = name.toLowerCase();

			if ( !isXML ) {
				ret = elem.getAttribute( name ) != null ?
					lowercaseName :
					null;
			}
			return ret;
		},

		set: function( elem, value, name ) {
			if ( value === false ) {

				// Remove boolean attributes when set to false
				jQuery.removeAttr( elem, name );
			} else {
				elem.setAttribute( name, name );
			}
			return name;
		}
	};