How to select an option by its option text using jQuery
Okay so here is a select list below and you need to choose an option by text so you can mark it as selected or trigger a change etc.
Select from option value is pretty easy and it is as below:
So now selecting by text, If you are using jQuery and if you have an older version than 1.9 the following will work choosing by text.
$('select option[value="label"]').attr('selected', true);
For more recent versions of jQeury the following works.
© Heshan Wanigasooriya.RSS
$('select option:contains("label")').attr('selected', true);
🍪 This site does not track you.