Paolo Bergantino Paolo Bergantino - 5 months ago 14x
Javascript Question

jQuery get specific option tag text

All right, say I have this:

<select id='list'>
<option value='1'>Option A</option>
<option value='2'>Option B</option>
<option value='3'>Option C</option>

What would the selector look like if I wanted to get "Option B" when I have the value '2'?

Please note that this is not asking how to get the selected text value, but just any one of them, whether selected or not, depending on the value attribute. I tried:


But it is not working.


It's looking for an element with id list which has a property value equal to 2. What you want is the option child of the list.

$("#list option[value='2']").text()