Jquery Dropdownlist Select Change
RED BLACK BLUE WHITE PINK
i not to want $('#COLOR').val(2);
i want $('#COLOR').val('RED');
How to make ?
Thank开发者_高级运维 You.
To select by value, pass that into the .val(newValue)
call, like this:
$('#COLOR').val('0');
This will select "RED" because it has value="0"
for it's <option>
element.
For the updated question: to select by text there are a few approaches, for example:
$("#COLOR").val(function() {
return $('option', this).filter(function() {
return this.innerHTML == 'RED';
}).attr('value');
});
You can give it a try here.
Can you make the value "RED", which will allow you to do what you want? Or do you have to keep the same HTML. For example
<option value="RED">RED</option>
精彩评论