This question is specifically aimed towards Select2 v4
How do I get the selected Value
for a Select2
dropdown?
I have tried the following:
jQuery('#Dropdown').val()
jQuery('#Dropdown').select2().val()
and neither seem to give me the Value of the selected element. I have made sure that there is a selected item when running this code.
select2 do not provide any direct method to get selected options attribute values. You need to get selected option element in select2 and then find its attribute ID:
jQuery('#Dropdown').select2().find(":selected").attr("id");
which can be narrowed down to:
jQuery("#Dropdown :selected").attr("id");
Try this:
$('#Dropdown').select2('data')[0].text;
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