Check empty string instead of specified as specified is inconsistent on the name attribute. Fixes #9148.

This commit is contained in:
timmywil 2011-05-06 13:49:20 -04:00
parent f7f8450041
commit c72b0f3256
2 changed files with 5 additions and 3 deletions

View file

@ -491,8 +491,8 @@ if ( !jQuery.support.getSetAttribute ) {
return elem.getAttribute( name ); return elem.getAttribute( name );
} }
ret = elem.getAttributeNode( name ); ret = elem.getAttributeNode( name );
// Return undefined if not specified instead of empty string // Return undefined if nodeValue is empty string
return ret && ret.specified ? return ret && ret.nodeValue !== "" ?
ret.nodeValue : ret.nodeValue :
undefined; undefined;
}, },

View file

@ -144,7 +144,7 @@ test("attr(Hash)", function() {
}); });
test("attr(String, Object)", function() { test("attr(String, Object)", function() {
expect(57); expect(58);
var div = jQuery("div").attr("foo", "bar"), var div = jQuery("div").attr("foo", "bar"),
fail = false; fail = false;
@ -164,6 +164,8 @@ test("attr(String, Object)", function() {
equals( jQuery("#name").attr("name"), "something", "Set name attribute" ); equals( jQuery("#name").attr("name"), "something", "Set name attribute" );
jQuery("#name").attr("name", null); jQuery("#name").attr("name", null);
equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); 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); jQuery("#check2").prop("checked", true).prop("checked", false).attr("checked", true);
equals( document.getElementById("check2").checked, true, "Set checked attribute" ); equals( document.getElementById("check2").checked, true, "Set checked attribute" );