In select2 how can I alert the option being selected for a multiple select?
This is my code for trigger when select2 option is being selected:
<script>
$("#list").select2();
$('#list').on("select2-selecting", function(e) {
alert(this.value);
});
</script>
This will only alert the already selected value. Not the option that I am selecting.
I can't also do this:
var test = $('#list').val();
alert(test);
Since it will only alert the already selected options as well.
What I want is to alert the option that is still being selected. So if you click the drop-down and select an option it will alert the value of that option.
The first option is selected by default. Sorry I forgot to mention this