Reputation: 4198
I've created quite interesting html contraption like this
<div class="alert alert-info" id="1">
<select name="first" id="sel-1-1">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select name="second" id="sel-2-1">
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
Now my question is, how to push values of all selected options in div, inside array using jquery? Have no idea where to start.
Upvotes: 1
Views: 1328
Reputation: 337560
You can use map()
to create an array of the selected values:
var selectedValueArray = $('.alert select').map(function() {
return $(this).val();
}).get();
Upvotes: 3
Reputation: 1858
Use this:
var new_item = '<option value="3">Three</option>';
$('.alert select').append(new_item);
Upvotes: 0