]> source.dussan.org Git - jquery.git/commitdiff
Check empty string instead of specified as specified is inconsistent on the name...
authortimmywil <tim.willison@thisismedium.com>
Fri, 6 May 2011 17:49:20 +0000 (13:49 -0400)
committertimmywil <tim.willison@thisismedium.com>
Fri, 6 May 2011 17:49:20 +0000 (13:49 -0400)
src/attributes.js
test/unit/attributes.js

index c22e89b711d4ec340e40118ed59f023e6420bc48..86f2d74a7a43aed97bfc1fc40b6a0068a032b955 100644 (file)
@@ -491,8 +491,8 @@ if ( !jQuery.support.getSetAttribute ) {
                                return elem.getAttribute( name );
                        }
                        ret = elem.getAttributeNode( name );
-                       // Return undefined if not specified instead of empty string
-                       return ret && ret.specified ?
+                       // Return undefined if nodeValue is empty string
+                       return ret && ret.nodeValue !== "" ?
                                ret.nodeValue :
                                undefined;
                },
index 257d02d09e6d05b861ce9a9757d509d6a84595ec..e019823646d8eb98398293d1a99509dfacd68a21 100644 (file)
@@ -144,7 +144,7 @@ test("attr(Hash)", function() {
 });
 
 test("attr(String, Object)", function() {
-       expect(57);
+       expect(58);
 
        var div = jQuery("div").attr("foo", "bar"),
                fail = false;
@@ -164,6 +164,8 @@ test("attr(String, Object)", function() {
        equals( jQuery("#name").attr("name"), "something", "Set name attribute" );
        jQuery("#name").attr("name", null);
        equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
+       var $input = jQuery("<input>", { name: "something" });
+       equals( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
 
        jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true);
        equals( document.getElementById("check2").checked, true, "Set checked attribute" );