how can I get value of unselected option in Select2 using select2:unselect
$('#mySelect').on("select2:unselect", function(e){
var unselected_value = $('#mySelect').val(); // using this shows 'null'
// or using below expression also shows 'null'
var unselected_value = $('#mySelect :selected').val();
alert(unselected_value);
}).trigger('change');
in above code alert shows 'null'
I need to use select2:unselect
because 'change' event will sense :select
and :unselect
both.
Actually, the data value is inside the event Object. It would be useful if you are dealing with select2 multiple values.
function(e){
console.log(e.params.data)
}
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