javascript - how to get all select option values using jquery -
i have select list
<select name="select-choice-min" id="mainmenu" data-mini="true"> <option value="10">10</option> <option value="11">11</option> ... </select> i tried
var arr = new array(); var sval = $("#mainmenu option").val(); arr.push(sval); but on alerting arr variable i'm getting first value 10, 10, 10, ...
so, how select option values?
try this
loop through #mainmenu option using .each() appropraite values using $(this).val() push using arr.push($(this).val());
var arr = new array(); $('#mainmenu option').each(function(){ arr.push($(this).val()); }); console.log(arr)
Comments
Post a Comment