bootstrap 4 accordion not working correctly it work only for first element

Sharifur Robin picture Sharifur Robin · Jan 17, 2018 · Viewed 11.4k times · Source

this accordion code not working in my html project. I tried too many time but failed to worked it successfully.

also tried w3school snippet above. first one is working very nice but whenever I am trying to collapse second one it not working. it will collapse for couple of milli seconds after that it will automatically get display none property.

I am also tried to active collapse via jquery but the result is same.

Answer

JSEvgeny picture JSEvgeny · Jan 17, 2018

Here is working fiddle for you

I think you simply forget to include jQuery before the bootstrap script.

Simply check your imports, should look somehow like this:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

and jQuery import on top of all that