HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptCritical

jQuery get specific option tag text

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
jquerytagtextoptionspecificget

Problem

Suppose I have a drop-down list like:


    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 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.