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.

3
  • 1
    Any errors in the console? Commented Sep 15, 2017 at 13:05
  • No errors at all. Commented Sep 15, 2017 at 13:11
  • 1
    I'm not sure it's a duplicate, but it might be: stackoverflow.com/questions/18615108/… Commented Sep 15, 2017 at 13:12

1 Answer 1

2

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

 $('#idColor').on('change', function(e) {
     console.log($('#idColor').val());
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.