diff options
author | John Resig <jeresig@gmail.com> | 2011-05-03 21:44:42 -0400 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2011-05-03 21:44:42 -0400 |
commit | a9d9f8c5422f171d9c451385fcfd7ed1661ec514 (patch) | |
tree | 059c5c638a40b896485ef0d7761832fdca448a63 /src/attributes.js | |
parent | bfad45fe4510db78a38170752ccc9c9efe5f38b6 (diff) | |
download | jquery-a9d9f8c5422f171d9c451385fcfd7ed1661ec514.tar.gz jquery-a9d9f8c5422f171d9c451385fcfd7ed1661ec514.zip |
If no hook is provided, and a boolean property exists, use that to return an attribute-style value for boolean attributes. Fixes #9079.
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/attributes.js b/src/attributes.js index 2da2e1639..9db69abcc 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -285,8 +285,7 @@ jQuery.extend({ attrFix: { // Always normalize to ensure hook usage - tabindex: "tabIndex", - readonly: "readOnly" + tabindex: "tabIndex" }, attr: function( elem, name, value, pass ) { @@ -327,20 +326,25 @@ jQuery.extend({ // Set boolean attributes to the same name if ( value === true && !rspecial.test( name ) ) { - value = name; + value = name.toLowerCase(); } elem.setAttribute( name, "" + value ); return value; } + } else if ( hooks && "get" in hooks && notxml ) { + return hooks.get( elem, name ); + } else { + var boolProp = elem[ jQuery.propFix[ name ] || name ]; - if ( hooks && "get" in hooks && notxml ) { - return hooks.get( elem, name ); + if ( typeof boolProp === "boolean" ) { + return boolProp ? + name.toLowerCase() : + undefined; } else { - ret = elem.getAttribute( name ); // Non-existent attributes return null, we normalize to undefined @@ -399,7 +403,9 @@ jQuery.extend({ } }, - propFix: {}, + propFix: { + readonly: "readOnly" + }, prop: function( elem, name, value ) { var nType = elem.nodeType; @@ -441,6 +447,7 @@ jQuery.extend({ // IE6/7 do not support getting/setting some attributes with get/setAttribute if ( !jQuery.support.getSetAttribute ) { jQuery.attrFix = jQuery.extend( jQuery.attrFix, { + readonly: "readOnly", "for": "htmlFor", "class": "className", maxlength: "maxLength", |