How to get all options of a select using jQuery?
How can I get all the options of a select through jQuery by passing on its ID?
I am only looking to get their values, not the text.
$("#id option").each(function()
{
// Add $(this).val() to your list
});
example
<select id="members" >
<option value="">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
var memberID = '';
$("#members option").each(function()
{
if($(this).val() != null && $(this).val() != '') {
memberID = $(this).val();
}
});