Home > Back-end >  The collapse effect is not working- bootstrap
The collapse effect is not working- bootstrap

Time:11-05

I tried to make a button that displays the hidden content when revealed using bootstrap but it's not working. Any Suggestions

<button  type="button" data-toggle="collapse" data-target="#ho2" aria-expanded="false" aria-controls="ho2">Get Started</button>
                <div  id="ho2">
                    <div >
                       Hello World!
                    </div>
                </div>

CodePudding user response:

If you're using Bootstrap 5, then:

  • change data-toggle="collapse" (Bootstrap 4) to data-bs-toggle="collapse" and
  • change data-target="#ho2" (Bootstrap 4) to data-bs-target="#ho2".

CodePudding user response:

Changed the data attr to data-bs-*(for BS5).
If correct BS js file and css file are included it should work.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA /3y gxIOqMEjwtxJY7qPCqsdltbNJuaOe923 mo//f6V8Qbsw3" crossorigin="anonymous"></script>

<button  type="button" data-bs-toggle="collapse" data-bs-target="#ho2" aria-expanded="false" aria-controls="ho2">Get Started</button>
<div  id="ho2">
  <div >
    Hello World!
  </div>
</div>

  • Related