Kishore Kumar
Kishore Kumar

Reputation: 939

How to get the specific option value of a dropdown by passing the option text in jquery

I am using the below line to get the value of a specific option of a dropdown, it is working in IE, but not working in Chrome.

$("#idDescription option[text='Business']").val();

Upvotes: 0

Views: 58

Answers (3)

Aleksandar Matic
Aleksandar Matic

Reputation: 799

$("#idDescription option").filter(function() { 
    return $(this).text() === 'Business';
})
.first()
.attr("value");

Upvotes: 0

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48367

Please try this:

$("#idDescription").find("option:contains('Business')").val();

Upvotes: 1

svantetic
svantetic

Reputation: 300

Use :contains pseudoselector.

$('#idDescription option:contains("Business")').val()

Upvotes: 1

Related Questions