M
M
maks789452021-06-25 23:51:57
JavaScript
maks78945, 2021-06-25 23:51:57

Why does select2 only apply to the last element?

Good day,
I have several selects and I want to use select2 for all of them

This is how the html looks like

<select class="select2 form-control" multiple="multiple" data-select2-id="select2-with-tags">
  <option>1</option>
</select>
<select class="select2 form-control" multiple="multiple" data-select2-id="select2-with-tags">
  <option>1</option>
</select>
<select class="select2 form-control" multiple="multiple" data-select2-id="select2-with-tags">
  <option>1</option>
</select>
<select class="select2 form-control" multiple="multiple" data-select2-id="select2-with-tags">
  <option>1</option>
</select>


But when initialized by class, select2 will only apply to the last drop-down list, I initialize like this Tell me what I'm doing wrong
$(".select2").select2()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dymok, 2021-06-26
@maks78945

Use different attribute valuesdata-select2-id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question