if ( elem ) {
hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];
- if ( hooks && "get" in hooks && (ret = hooks.get( elem )) !== undefined ) {
+ if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
return ret;
}
hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];
// If set returns undefined, fall back to normal setting
- if ( !hooks || ("set" in hooks && hooks.set( this, val ) === undefined) ) {
+ if ( !hooks || ("set" in hooks && hooks.set( this, val, "value" ) === undefined) ) {
this.value = val;
}
});
// Use this for any attribute on a form in IE6/7
// And the name attribute
- formHook = jQuery.attrHooks.name = {
+ formHook = jQuery.attrHooks.name = jQuery.attrHooks.value = jQuery.valHooks.button = {
get: function( elem, name ) {
var ret = elem.getAttributeNode( name );
// Return undefined if not specified instead of empty string
});
test("attr(String)", function() {
- expect(32);
+ expect(34);
equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
ok( !!~jQuery("#dl").attr("style").indexOf("position"), "Check style attribute getter, also normalize css props to lowercase" );
ok( !!~jQuery("#foo").attr("style", "position:absolute;").attr("style").indexOf("position"), "Check style setter" );
+ // Check value on button element (#1954)
+ var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
+ equals( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" );
+ equals( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" );
+
ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
});
});
test("val()", function() {
- expect(23);
+ expect(25);
document.getElementById("text1").value = "bla";
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
checks.remove();
+
+ var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
+ equals( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
+ equals( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
});
var testVal = function(valueObj) {