I am using select v4.0.3. How do I get the replaced/previous value of the select element? I already attached a 'change' listener but I can't seem to find the previous value.
Previously selected value can be acquired by using select2:selecting
event
see the codes here: https://codepen.io/jacobgoh101/pen/ZpGvkx?editors=1111
$('select').on('select2:selecting', function (evt) {
console.log('previously selected ' + $('select').val());
});
$('select').on('select2:select', function (evt) {
console.log('now selected ' + $('select').val());
});
You can do it easily in selecting event
$(this).on("select2-selecting", function (e) {
var curentValue = e.val;
var previousValue = $(this).val();
});
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