I have many options in my dropdownlist like:
<option value="1">it's me</option>
I need to select the option who have value it's me inside the tag, not by attribute like 1
.
How can I do this using jQuery?
This question is related to
javascript
jquery
html
css
events
$("#dropdownList option[text='it\'s me']").attr("selected","selected");
You can just do this:
$('#myCombobox').val(1)
val() should handle both cases
<option value="1">it's me</option>
$('select').val('1'); // selects "it's me"
$('select').val("it's me"); // also selects "it's me"
jQuery("select#cboDays option[value='Wednesday']").attr("selected", "selected");
$('#userZipFiles option').prop('selected', function() {
return this.defaultSelected;
});
One line of jQuery does it all!
$("#myCombobox option[text='it\'s me']").attr("selected","selected");
This is working fine:
$('#country').val($("#country option:contains('It\'s Me')").val());
Source: Stackoverflow.com