Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script> </head> <body> <select> <option value="0">Value1</option> <option value="1">Value2</option> </select> <script> let text = 'Value2'; $("select option").filter(function() { //may want to use $.trim in here return $(this).text() == text; }).val('selected'); </script> </body> </html>