Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda