Does anyone know how can I get all values in the select by Jquery?
Example:
<select name="group_select" id="group_select">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
Which I want to get all option values (a,b and c) from select (without selected any option) by using jquery
var values = $("#group_select>option").map(function() { return $(this).val(); });
The following will give you an array of the <option>
values
var values = $.map($('#group_select option'), function(e) { return e.value; });
// as a comma separated string
values.join(',');
Here's a Working Demo. add /edit to the URL to see the code.
This will iterate through all the options and give you their values.Then you can either append them to an array or manipulate them individually.
$('#group_select option').each(function(){
$(this).val()
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With