javascript - Selecting option value of selected element with jquery -


i'm trying use jquery select option value of selected element in html dropdown.

html

<select class="select1">     <option value ="0">" + state.greens[0].name + "</option>     <option value ="1">" + state.greens[1].name + "</option>     <option value ="2">" + state.greens[2].name + "</option> </select> 

the option values represent index position in array can load generate additional data objects within them.

i'm trying use jquery grab option value of whatever dropdown element selected.

right i'm using code it's not working:

jquery

var = $(".select1 option:selected"); 

however it's not bringing "1", "2", "3", etc.

when run console.log(a) following:

console log

not sure what's happening.

the idea can use variable load data state.greens[a].price, state.greens[a].ingredients, etc.

you there. give:

var = $(".select1 option:selected").attr("value"); 

or give this:

var = $(".select1").val(); 

you need value of <select>.


Comments