Try the :contains()
selector:
$('#Test option:contains("DEF")')
Note that :contains()
is a wildcard search. If you need an exact match, I think you'll just need to iterate or filter the options and check the text()
. Here's one possibility:
console.log(getOptionByText('Test', 'DEF'));
function getOptionByText(id, value) {
return $('#' + id).find('option').filter(function() {
return $(this).text() == value;
});
}