From 25118e22a204c5396f1265feb5cbfd71f35033e3 Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 18 May 2011 11:46:22 -0400 Subject: [PATCH] Handle unset value attributes consistently depending on property existence. Supplements #9328. --- src/attributes.js | 7 ++++--- test/unit/attributes.js | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index bb2c2f7d8..ba820145a 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -343,8 +343,8 @@ jQuery.extend({ return value; } - } else if ( hooks && "get" in hooks && notxml ) { - return hooks.get( elem, name ); + } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) { + return ret; } else { @@ -495,12 +495,13 @@ boolHook = { // Use the formHook for button elements in IE6/7 (#1954) jQuery.attrHooks.value = { get: function( elem, name ) { + var ret; if ( formHook && jQuery.nodeName( elem, "button" ) ) { return formHook.get( elem, name ); } return name in elem ? elem.value : - elem.getAttribute( name ); + null; }, set: function( elem, value, name ) { if ( formHook && jQuery.nodeName( elem, "button" ) ) { diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 546aaffa5..c4ed7d30f 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -40,7 +40,7 @@ test("jQuery.attrFix/jQuery.propFix integrity test", function() { }); test("attr(String)", function() { - expect(43); + expect(45); equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); @@ -126,6 +126,8 @@ test("attr(String)", function() { ok( jQuery("
").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); equal( jQuery("
").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." ); + equal( jQuery("
").attr("value"), undefined, "An unset value on a div returns undefined." ); + equal( jQuery("").attr("value"), "", "An unset value on an input returns current value." ); }); if ( !isLocal ) {