I need to get the selected text and value from the optGroup selectList below on the click of a button. So something like?
$("#addButton").click(function () {
var selected = ???
});
<select name="list">
<optgroup label="mammals">
<option>dog</option>
<option>cat</option>
<option>rabbit</option>
<option>horse</option>
</optgroup>
<optgroup label="reptiles">
<option>iguana</option>
<option>snake</option>
</optgroup>
</select>
You can use
Attribute Equalsselector andvalmethod.valmethod return the value of selectedoption. However as your option tags have no value attributes,valreturns thetextof the selected option.http://jsfiddle.net/DRDsS/