aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-05-03 14:48:36 -0400
committertimmywil <tim.willison@thisismedium.com>2011-05-03 14:48:36 -0400
commit4ac2fdda2c26e9b64502b9ef50748427bed2f3c6 (patch)
treeb87166d679cf3beb462b02e1763ac1fe5d74af4e
parent6d2fd57f452398123f8edefa25eef8045d1b586e (diff)
downloadjquery-4ac2fdda2c26e9b64502b9ef50748427bed2f3c6.tar.gz
jquery-4ac2fdda2c26e9b64502b9ef50748427bed2f3c6.zip
Fix setting value attributes on option elements. Fixes #9071.
-rw-r--r--src/attributes.js2
-rw-r--r--test/unit/attributes.js4
2 files changed, 4 insertions, 2 deletions
diff --git a/src/attributes.js b/src/attributes.js
index 017a32da4..2da2e1639 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -199,7 +199,7 @@ jQuery.fn.extend({
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, "value" ) === undefined) ) {
+ if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
this.value = val;
}
});
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 37e854d06..b1cfe3db2 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -447,7 +447,7 @@ test("removeProp(String)", function() {
});
test("val()", function() {
- expect(25);
+ expect(26);
document.getElementById("text1").value = "bla";
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
@@ -513,6 +513,8 @@ test("val()", function() {
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" );
+
+ equals( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" );
});
var testVal = function(valueObj) {