I am trying to bind onclick to select input element with select2 initialization.
I want to bind a handler when the drop-down is clicked or focused.
<select class="form-control" id="type" name="type" required="required">
<option value="breakfast" <?= ($type == 'breakfast')? 'selected' : '';?>>Breakfast</option>
<option value="snacks" <?= ($type == 'snacks')? 'selected' : '';?>>Snacks</option>
</select>
Here's the js part:
$('#type').select2({}).on("select2-selecting", function(e) {
console.log('not working');
});
I also tried "select2-open/opening" but to no avail.
How do I make the event binding work?