I have Multiselect dropdown. Whenever there is a select or deselect, I need to get the value. I am using change event, but struggling to get which option was selected/deselected.
//all options
var all=[];
$('#multiple').each(function(i, selected){
all[i] = $(selected).text();
});
//selected options
var foo = [];
$('#multiple :selected').each(function(i, selected){
foo[i] = $(selected).text();
});
// unselected options
var de= $.grep(all, function(element) {
return $.inArray(element, foo) !== -1;
});
In the foo
array are the selected values
In the de
array are the unselected values
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