Reputation: 4404
I can't recall how to get the index of the option from the text without using a for loop. Is there an easy way?
Let's say I have a select like this:
<select id="prefix-select" name="survey[Prefix]" onchange="changeMade();">
<option value="0">Mr.</option>
<option value="1">Mrs.</option>
<option value="2">Ms.</option>
<option value="3">Dr.</option>
<option value="4">Sr.</option>
<option value="5">Sra.</option>
<option value="6">Srta.</option>
</select>
Now I want to get the index when I have a text of '.Ms'
Upvotes: 0
Views: 2191
Reputation: 4888
Jquery way:
var str = "Sr."; index = $("#prefix-select > option:contains("+str+")").index())
Upvotes: 2