patternjavascriptCritical
jQuery get specific option tag text
Viewed 0 times
jquerytagtextoptionspecificget
Problem
Suppose I have a drop-down list like:
Given the value
I tried
Option A
Option B
Option C
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.Solution
It's looking for an element with id
What you want is the
list which has a property value equal to 2.What you want is the
option child of the list:$("#list option[value='2']").text()Code Snippets
$("#list option[value='2']").text()Context
Stack Overflow Q#196684, score: 1148
Revisions (0)
No revisions yet.