Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

403
Views
¿Cómo evitar que se muestre el colapso de Bootstrap según la condición? bs5

Necesito evitar que el panel plegable se muestre o se abra si un valor específico es nulo. parece facil pero hice muchos intentos y nada funciono.

HTML

 <a href="#" data-bs-toggle="collapse" data-bs-target="#infoBox" aria-expanded="false" aria-controls="infoBox"></i> <div class="collapse m-3" id="infoBox">some ifos ...</div>

Primer intento:

 var someVal; var infoBox = document.getElementById('infoBox') infoBox.addEventListener('show.bs.collapse', function () { // console.log(e.target); if (someVal == null) return; })

Segundo intento:

 var someVal; var infoBox = document.getElementById('infoBox'); var bsCollapse = new bootstrap.Collapse(infoBox, { show: false, dispose: true }) infoBox.addEventListener('show.bs.collapse', function (e) { // console.log(e.target); if (someVal == null) return bsCollapse; })

Ninguno de ellos está trabajando

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar la función e.preventDefault() para evitar el incumplimiento.

 var toggle = false; $("#wrapper").on('show.bs.collapse', function (e) { if (!toggle) { e.preventDefault(); } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <div id="wrapper"> <a href="#" data-bs-toggle="collapse" data-bs-target="#infoBox" aria-expanded="false" aria-controls="infoBox" id="myCollapsible">press me</a> <div class="collapse m-3" id="infoBox">some ifos ...</div> </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!