I have a dropdown similar to the following:
<select type="select" id="ddl">
<option value="0">Select...</option>
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Green</option>
<option value="4">Yellow</option>
</select>
I need to get the value of an option when I have the text, independent of whether anything is selected or not.
I tried $('#ddl[text=Blue]).value()
, but that wouldn't work. I don't know what else to try.
Thanks.
SELECT EXAMPLE FIXED (I copy/pasted the wrong line - sheesh! ;) )
var color = "Red";
alert($('#ddl option:contains("' + color + '")').attr("value"));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments