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

226
Visualizações
Bootstrap - Only Expand/Collapse with Specific Radio Button Clicked

I am trying to create some website functionality where there are two radio buttons "Yes" and "No", and when "Yes" is selected, it expands the collapsible portion of HTML, and when "No" is selected, it collapses it. The issue I am running into is if you continuously click the "Yes" radio button, it will expand and collapse it. I only want one or the other depending on which button is selected. This is what I have come up with:

HTML:

        <div class="row gy-3">
            <label><b>Have you ever applied for a job with any of the companies listed above as an employee or as a temporary employee? *</b></label>
                <div class="col-md-4">
                    <div class="form-check">
                        <input type="radio" class="form-check-input" id="validationFormCheck2" name="radio-stacked" value="Yes" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample" required>
                        <label class="form-check-label" for="validationFormCheck2">Yes</label>
                    </div>
                    <div class="form-check mb-3">
                        <input type="radio" class="form-check-input" id="validationFormCheck3" name="radio-stacked" value="No" required>
                        <label class="form-check-label" for="validationFormCheck3">No</label>
                        <div class="invalid-feedback">More example invalid feedback text</div>
                    </div>
                    <div class="collapse" id="collapseExample">
                        <div class="card card-body">
                            Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
                        </div>
                    </div>
                </div>
            </div>

JS:

$('#employmentForm input').on('change', function() {
   var value = $('input[name=radio-stacked]:checked', '#employmentForm').val();
   if (value === "Yes") {
       var myCollapse = document.getElementById('collapseExample')
       var bCollapse = new bootstrap.Collapse(myCollapse, {
         show: true
       })
   } else if (value === "No") {
       var myCollapse = document.getElementById('collapseExample')
       var bsCollapse = new bootstrap.Collapse(myCollapse, {
           dispose: true 
       })
   }
});
about 4 years ago · Juan Pablo Isaza
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