Suppose I have a drop-down list like:
<select id='list'> <option value='1'>Option A</option> <option value='2'>Option B</option> <option value='3'>Option C</option> </select>
Given the value '2' (i.e., using a specific value, not necessarily the selected one), what selector can I use to get "Option B"?
I tried $("#list[value='2']").text();, but it is not working.
It’s looking for an element with id
listwhich has a propertyvalueequal to2.What you want is the
optionchild of thelist: