Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
Select2 open another select2 on 1st select2 open event

$(".js-example-events").select2();

$('.js-example-events').on("select2:open", function () {
    $("#s1").select2("open");
});

function test(){
    $("#s1").select2("open");
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
                                <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
                                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/css/select2.min.css"/>

<select class="js-example-events" style="width:300px;">
<option>Select One</option>
<option>Select1</option>
</select>

<select class="js-example-events" id="s1" style="width:300px;">
<option>Selects Two</option>
<option>Select1</option>
</select>

<button onclick="test()">
Test
</button>

I want to open 2 select2 at a time.

It works when I use a button click event, but not when I use select2 open event

<select class="js-example-events" style="width:300px;">
    <option>Select One</option>
    <option>Select1</option>
</select>

<select class="js-example-events" id="s1" style="width:300px;">
    <option>Selects Two</option>
    <option>Select1</option>
</select>

<button onclick="test()">Test</button>

JS

$(".js-example-events").select2();

$('.js-example-events').on("select2:open", function () {
    $("#s1").select2("open");  // not working here
});

function test(){
    $("#s1").select2("open"); // but work here well
}

Working JSFiddle

https://jsfiddle.net/gqo5cL6x/

select2("open"); is not working

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use two case:

Case 1: Not run before select2 because you run before select2, it changes on HTML. Therefore you call function not run. You use code below:

$(".js-example-events").on("click", function () { 
   $("#s1").select2();
   $("#s1").select2("open");
   $(this).select2();
   $(this).select2("open");
});

Case 2: Keep your code you need call event to code below:

$(".js-example-events").select2();

$("span[class='select2-selection select2-selection-- 
 single']").on("click", 
function () { 
   $("#s1").select2("open");
  $(this).select2("open");
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda