Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of select2:unselect

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.

like image 602
Vipin Kr. Singh Avatar asked Dec 25 '15 14:12

Vipin Kr. Singh


1 Answers

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)
}
like image 63
Chun Avatar answered Oct 16 '22 07:10

Chun