Selecting options in a select via JQuery
html, html-select, javascript, jquery
Solution
You can use the `:contains()` selector:
$('option:contains("B")').prop('selected', true);
Alternatively:
$('option')
.filter(function() {
return this.text == 'B';
})
.prop('selected', true);
Problem
I have a select with the following options: ``` <select> <option value="1">A</option> <option value="2">B</option> <option value="3">C</option> </select> ``` I don't know what the values are, but in my JQuery code, I want to select option two because I know that the text is B (but nothing else). How can it be done?