Home > Article > Web Front-end > How to Select an Option in a jQuery Select Control by Text Description?
When working with select controls, you may want to select an option based on its text description rather than its value. In jQuery, you can achieve this using a few techniques.
One approach for jQuery versions 1.6 and above is to filter the options by their text and then set the selected property:
<code class="js">var text1 = 'Two'; $("select option").filter(function() { return $(this).text() == text1; }).prop('selected', true);</code>
This code selects the option with the text "Two" and sets it as the selected option.
The above is the detailed content of How to Select an Option in a jQuery Select Control by Text Description?. For more information, please follow other related articles on the PHP Chinese website!