0

I am trying to trigger a function when a value of a Select2 is selected. The select2 has name of colors.

$('#idColor').on('select2:selecting', function(e) {
    console.log($('#idColor').val());
});

Example: I select the option Blue and nothing happened. Then I select the color Red and the console shows Blue.

The Select2 widget is in a Yii2 project created by another person. So I couldn't find its documentation web.

Select2 example

Maybe I have a similar problem to this, but this person use Backbone.js: Click and Change event not working for jquery-select2 options

I am learning jQuery, so maybe I am doing something wrong.

Roby Sottini
  • 2,117
  • 6
  • 48
  • 88

1 Answers1

2

Could be you are not using the right event Try using onChange

 $('#idColor').on('change', function(e) {
     console.log($('#idColor').val());
 });
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107