B
B
BuBux2020-04-10 00:47:00
css
BuBux, 2020-04-10 00:47:00

How to hang an event on select class="form-control select2"?

<div class="form-group col-md-6" style="overflow:hidden; padding-left: 0px;">
    <label for="field-1" class="control-label">Направление</label>
                                            
    <?php if (is_array($directions)): ?>
        <select id="direction" class="form-control select2" name="direction[]" style="width: 100%;" multiple>
            <?php foreach ($directions as $direction): ?>
                <option value="<?=$direction['ID']?>">
                    <?php echo $direction['NAME']; ?>
                </option>
            <?php endforeach; ?>
        </select>
    <?php endif; ?>
</div>

How can I hang the change event? And it is desirable that the appeal be by id.
Tried like this:
$(document).on('change', '#direction', function () {
    console.log('yes');
});

But nothing works. I read to the point that it is necessary to handle select2 differently, but I did not find how exactly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
origami1024, 2019-10-12
@MRcracker

Class in bootstrap .text-center

F
felony13twelve, 2020-04-10
@BuBux

$("#direction").change(function () {
    console.log('yes');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question