Can someone explain this behavior:
I think you want to try,
$('#test').val(2);
none
is selected
(or default selected) if the drop-down value not exists.
Demo
The issue comes in Blackberry 4.7
having attributes.value
The change in 1.9 version
and 1.10 version
are
jQuery 1.9.1 hook
jQuery.extend({
valHooks: {
option: {
get: function( elem ) {
// attributes.value is undefined in Blackberry 4.7 but
// uses .value. See #6932
var val = elem.attributes.value;
return !val || val.specified ? elem.value : elem.text;
}
},
And jQuery 1.10 hook
jQuery.extend({
valHooks: {
option: {
get: function( elem ) {
// Use proper attribute retrieval(#6932, #12072)
var val = jQuery.find.attr( elem, "value" );
return val != null ?
val :
elem.text;
}
}
Read #6932 Blackberry 4.7: .val() on empty option fails