When an option list is dynamically created from an ajax call I want to set one of the options as Selected based the first few characters of the option text. Using this HTML:
<select id="test">
<option value="bird">123 Bird</option>
<option value="bat">456 Bat</option>
<option value="cat">768 Cat</option>
<option value="dog">890 Dog</option>
</select>
I can use this jQuery that will set the selected based on the VALUE
$(document).ready(function () {
$("#test option[value^='ca']").prop('selected', true);
});
But, I want to set the option selected based on the TEXT, and this does not work:
$(document).ready(function () {
$("#test option[text^='768']").prop('selected', true);
});
Here is a demo with both lines: http://jsfiddle.net/pfinigan/wzy7f5dr/13/
So, the question is how to select the option by the first portion of it's text??