I need set default selected value with text, here is my code:
HTML:
<select id="sel">
<option value="F">Firm</option>
<option value="G" selected="selected">Government</option>
<option value="I">Individual</option>
</select>
JavaScript:
$("#sel>option[text='Firm']).prop("selected", true);
it does not work, below value is 0:
$("#sel>option[text='Firm']).length
If I use attribute value, it works, but I need use text here.
Thanks.
It’s not possible to treat the text content of an element as if it were an attribute in CSS selector syntax.
You can write a filter to do it, however: