Renish Khunt Renish Khunt - 3 months ago 23
jQuery Question

jQuery select2 get value of select tag?

Hello Friends this is my code.

<select id='first'>
<option value='1'>First</option>
<option value='2'>Second</option>
<option value='3'>three</option>
</select>


this is my select2 code.

$("#first").select2();


below is code for getting selected value.

$("#first").val(); //it return 1,2,3. this is not return anything when i used select2 plugin.
OR
$("#first").select2('val'); // it return first,second,three


this is return a text like
first,second,three
and i want to get
1,2,3


means i need a value of select box not text please help.

Answer
$("#first").val(); // this will give you value of selected element. i.e. 1,2,3.
Comments