Skip to content

Commit

Permalink
Handle unset value attributes consistently depending on property exis…
Browse files Browse the repository at this point in the history
…tence. Supplements #9328.
  • Loading branch information
timmywil committed May 18, 2011
1 parent ba90af0 commit 25118e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/attributes.js
Expand Up @@ -343,8 +343,8 @@ jQuery.extend({
return value; return value;
} }


} else if ( hooks && "get" in hooks && notxml ) { } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
return hooks.get( elem, name ); return ret;


} else { } else {


Expand Down Expand Up @@ -495,12 +495,13 @@ boolHook = {
// Use the formHook for button elements in IE6/7 (#1954) // Use the formHook for button elements in IE6/7 (#1954)
jQuery.attrHooks.value = { jQuery.attrHooks.value = {
get: function( elem, name ) { get: function( elem, name ) {
var ret;
if ( formHook && jQuery.nodeName( elem, "button" ) ) { if ( formHook && jQuery.nodeName( elem, "button" ) ) {
return formHook.get( elem, name ); return formHook.get( elem, name );
} }
return name in elem ? return name in elem ?
elem.value : elem.value :
elem.getAttribute( name ); null;
}, },
set: function( elem, value, name ) { set: function( elem, value, name ) {
if ( formHook && jQuery.nodeName( elem, "button" ) ) { if ( formHook && jQuery.nodeName( elem, "button" ) ) {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/attributes.js
Expand Up @@ -40,7 +40,7 @@ test("jQuery.attrFix/jQuery.propFix integrity test", function() {
}); });


test("attr(String)", function() { test("attr(String)", function() {
expect(43); expect(45);


equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
Expand Down Expand Up @@ -126,6 +126,8 @@ test("attr(String)", function() {
ok( jQuery("<div/>").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); ok( jQuery("<div/>").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." );
equal( jQuery("<div/>").attr("title", "something").attr("title"), "something", "Set the title attribute." ); equal( jQuery("<div/>").attr("title", "something").attr("title"), "something", "Set the title attribute." );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
equal( jQuery("<div/>").attr("value"), undefined, "An unset value on a div returns undefined." );
equal( jQuery("<input/>").attr("value"), "", "An unset value on an input returns current value." );
}); });


if ( !isLocal ) { if ( !isLocal ) {
Expand Down

0 comments on commit 25118e2

Please sign in to comment.