Menu won't collapse while clicking on other items












0















I am trying to reproduce this on my own website :
https://www.bootply.com/bootply/WIu8eya2dQ#



Here is the code:



<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="list-group panel">
<a href="#menu1" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 1 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu1">
<a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu1sub1">
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 1 a</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 2 b</a>
<a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu1sub1sub1">
<a href="#" class="list-group-item">Subitem 3 c - item 1</a>
<a href="#" class="list-group-item">Subitem 3 c - item 2</a>
</div>
<a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
<a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu1sub1sub2">
<a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.1</a>
<a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.2</a>
</div>
</div>
<a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
<a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
</div>
<a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
<a href="#menu3" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 3 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu3">
<a href="#" class="list-group-item" data-parent="#menu3">3.1</a>
<a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="menu3sub2">
<a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 a</a>
<a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 b</a>
<a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 c</a>
</div>
<a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
</div>
<a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
<a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
</div>
<script src="/jquery/jquery-2.2.4.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


It works well but for some reason, when I expend an item, the ones already expanded do not collapse.










share|improve this question



























    0















    I am trying to reproduce this on my own website :
    https://www.bootply.com/bootply/WIu8eya2dQ#



    Here is the code:



    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <div class="list-group panel">
    <a href="#menu1" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 1 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu1">
    <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu1sub1">
    <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 1 a</a>
    <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 2 b</a>
    <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu1sub1sub1">
    <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
    <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
    </div>
    <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
    <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu1sub1sub2">
    <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.1</a>
    <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.2</a>
    </div>
    </div>
    <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
    <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
    </div>
    <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
    <a href="#menu3" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 3 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu3">
    <a href="#" class="list-group-item" data-parent="#menu3">3.1</a>
    <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="menu3sub2">
    <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 a</a>
    <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 b</a>
    <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 c</a>
    </div>
    <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
    </div>
    <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
    <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
    </div>
    <script src="/jquery/jquery-2.2.4.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


    It works well but for some reason, when I expend an item, the ones already expanded do not collapse.










    share|improve this question

























      0












      0








      0








      I am trying to reproduce this on my own website :
      https://www.bootply.com/bootply/WIu8eya2dQ#



      Here is the code:



      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <div class="list-group panel">
      <a href="#menu1" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1">
      <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1">
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 1 a</a>
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 2 b</a>
      <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1sub1">
      <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
      <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
      <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1sub2">
      <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.1</a>
      <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.2</a>
      </div>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
      <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
      <a href="#menu3" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 3 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu3">
      <a href="#" class="list-group-item" data-parent="#menu3">3.1</a>
      <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu3sub2">
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 a</a>
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 b</a>
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 c</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
      </div>
      <script src="/jquery/jquery-2.2.4.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


      It works well but for some reason, when I expend an item, the ones already expanded do not collapse.










      share|improve this question














      I am trying to reproduce this on my own website :
      https://www.bootply.com/bootply/WIu8eya2dQ#



      Here is the code:



      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <div class="list-group panel">
      <a href="#menu1" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1">
      <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1">
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 1 a</a>
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 2 b</a>
      <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1sub1">
      <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
      <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
      <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu1sub1sub2">
      <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.1</a>
      <a href="#" class="list-group-item" data-parent="#menu1sub1sub2">Subitem 5 e.2</a>
      </div>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
      <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
      <a href="#menu3" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">Item 3 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu3">
      <a href="#" class="list-group-item" data-parent="#menu3">3.1</a>
      <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="menu3sub2">
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 a</a>
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 b</a>
      <a href="#" class="list-group-item" data-parent="#menu3sub2">3.2 c</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
      </div>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
      <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
      </div>
      <script src="/jquery/jquery-2.2.4.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>


      It works well but for some reason, when I expend an item, the ones already expanded do not collapse.







      bootstrap-4 collapse






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 11:50









      JibejiJibeji

      437




      437
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The example you're showing is for Bootstrap 3, not Bootstrap 4.



          For accordion behavior in Bootstrap 4, the data-parent should be set in the collapse element instead of the element that is toggling the collapse (data-toggle="collapse").



          <div class="list-group" id="sidebar">
          <a href="#menu1" class="list-group-item" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1" data-parent="#sidebar">
          <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1" data-parent="#menu1sub1">
          <a href="#" class="list-group-item">Subitem 1 a</a>
          <a href="#" class="list-group-item">Subitem 2 b</a>
          <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub1">
          <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
          <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
          <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub2" data-parent="#menu1sub1sub2">
          <a href="#" class="list-group-item">Subitem 5 e.1</a>
          <a href="#" class="list-group-item">Subitem 5 e.2</a>
          </div>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
          <a href="#menu3" class="list-group-item" data-toggle="collapse">Item 3 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3" data-parent="#sidebar">
          <a href="#" class="list-group-item">3.1</a>
          <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3sub2" data-parent="#menu3">
          <a href="#" class="list-group-item">3.2 a</a>
          <a href="#" class="list-group-item">3.2 b</a>
          <a href="#" class="list-group-item">3.2 c</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
          </div>


          https://www.codeply.com/go/ao94agthVY






          share|improve this answer
























          • Thank you Zim !

            – Jibeji
            Nov 20 '18 at 12:45











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392398%2fmenu-wont-collapse-while-clicking-on-other-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The example you're showing is for Bootstrap 3, not Bootstrap 4.



          For accordion behavior in Bootstrap 4, the data-parent should be set in the collapse element instead of the element that is toggling the collapse (data-toggle="collapse").



          <div class="list-group" id="sidebar">
          <a href="#menu1" class="list-group-item" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1" data-parent="#sidebar">
          <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1" data-parent="#menu1sub1">
          <a href="#" class="list-group-item">Subitem 1 a</a>
          <a href="#" class="list-group-item">Subitem 2 b</a>
          <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub1">
          <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
          <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
          <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub2" data-parent="#menu1sub1sub2">
          <a href="#" class="list-group-item">Subitem 5 e.1</a>
          <a href="#" class="list-group-item">Subitem 5 e.2</a>
          </div>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
          <a href="#menu3" class="list-group-item" data-toggle="collapse">Item 3 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3" data-parent="#sidebar">
          <a href="#" class="list-group-item">3.1</a>
          <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3sub2" data-parent="#menu3">
          <a href="#" class="list-group-item">3.2 a</a>
          <a href="#" class="list-group-item">3.2 b</a>
          <a href="#" class="list-group-item">3.2 c</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
          </div>


          https://www.codeply.com/go/ao94agthVY






          share|improve this answer
























          • Thank you Zim !

            – Jibeji
            Nov 20 '18 at 12:45
















          1














          The example you're showing is for Bootstrap 3, not Bootstrap 4.



          For accordion behavior in Bootstrap 4, the data-parent should be set in the collapse element instead of the element that is toggling the collapse (data-toggle="collapse").



          <div class="list-group" id="sidebar">
          <a href="#menu1" class="list-group-item" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1" data-parent="#sidebar">
          <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1" data-parent="#menu1sub1">
          <a href="#" class="list-group-item">Subitem 1 a</a>
          <a href="#" class="list-group-item">Subitem 2 b</a>
          <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub1">
          <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
          <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
          <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub2" data-parent="#menu1sub1sub2">
          <a href="#" class="list-group-item">Subitem 5 e.1</a>
          <a href="#" class="list-group-item">Subitem 5 e.2</a>
          </div>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
          <a href="#menu3" class="list-group-item" data-toggle="collapse">Item 3 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3" data-parent="#sidebar">
          <a href="#" class="list-group-item">3.1</a>
          <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3sub2" data-parent="#menu3">
          <a href="#" class="list-group-item">3.2 a</a>
          <a href="#" class="list-group-item">3.2 b</a>
          <a href="#" class="list-group-item">3.2 c</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
          </div>


          https://www.codeply.com/go/ao94agthVY






          share|improve this answer
























          • Thank you Zim !

            – Jibeji
            Nov 20 '18 at 12:45














          1












          1








          1







          The example you're showing is for Bootstrap 3, not Bootstrap 4.



          For accordion behavior in Bootstrap 4, the data-parent should be set in the collapse element instead of the element that is toggling the collapse (data-toggle="collapse").



          <div class="list-group" id="sidebar">
          <a href="#menu1" class="list-group-item" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1" data-parent="#sidebar">
          <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1" data-parent="#menu1sub1">
          <a href="#" class="list-group-item">Subitem 1 a</a>
          <a href="#" class="list-group-item">Subitem 2 b</a>
          <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub1">
          <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
          <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
          <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub2" data-parent="#menu1sub1sub2">
          <a href="#" class="list-group-item">Subitem 5 e.1</a>
          <a href="#" class="list-group-item">Subitem 5 e.2</a>
          </div>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
          <a href="#menu3" class="list-group-item" data-toggle="collapse">Item 3 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3" data-parent="#sidebar">
          <a href="#" class="list-group-item">3.1</a>
          <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3sub2" data-parent="#menu3">
          <a href="#" class="list-group-item">3.2 a</a>
          <a href="#" class="list-group-item">3.2 b</a>
          <a href="#" class="list-group-item">3.2 c</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
          </div>


          https://www.codeply.com/go/ao94agthVY






          share|improve this answer













          The example you're showing is for Bootstrap 3, not Bootstrap 4.



          For accordion behavior in Bootstrap 4, the data-parent should be set in the collapse element instead of the element that is toggling the collapse (data-toggle="collapse").



          <div class="list-group" id="sidebar">
          <a href="#menu1" class="list-group-item" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1" data-parent="#sidebar">
          <a href="#menu1sub1" class="list-group-item" data-toggle="collapse">Subitem 1 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1" data-parent="#menu1sub1">
          <a href="#" class="list-group-item">Subitem 1 a</a>
          <a href="#" class="list-group-item">Subitem 2 b</a>
          <a href="#menu1sub1sub1" class="list-group-item" data-toggle="collapse">Subitem 3 c <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub1">
          <a href="#" class="list-group-item">Subitem 3 c - item 1</a>
          <a href="#" class="list-group-item">Subitem 3 c - item 2</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1sub1">Subitem 4 d</a>
          <a href="#menu1sub1sub2" class="list-group-item" data-toggle="collapse">Subitem 5 e <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu1sub1sub2" data-parent="#menu1sub1sub2">
          <a href="#" class="list-group-item">Subitem 5 e.1</a>
          <a href="#" class="list-group-item">Subitem 5 e.2</a>
          </div>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 2</a>
          <a href="#" class="list-group-item" data-parent="#menu1">Subitem 3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 2</a>
          <a href="#menu3" class="list-group-item" data-toggle="collapse">Item 3 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3" data-parent="#sidebar">
          <a href="#" class="list-group-item">3.1</a>
          <a href="#menu3sub2" class="list-group-item" data-toggle="collapse">3.2 <i class="fa fa-caret-down"></i></a>
          <div class="collapse" id="menu3sub2" data-parent="#menu3">
          <a href="#" class="list-group-item">3.2 a</a>
          <a href="#" class="list-group-item">3.2 b</a>
          <a href="#" class="list-group-item">3.2 c</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#menu3">3.3</a>
          </div>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 4</a>
          <a href="#" class="list-group-item" data-parent="#sidebar">Item 5</a>
          </div>


          https://www.codeply.com/go/ao94agthVY







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 12:17









          ZimZim

          186k47391374




          186k47391374













          • Thank you Zim !

            – Jibeji
            Nov 20 '18 at 12:45



















          • Thank you Zim !

            – Jibeji
            Nov 20 '18 at 12:45

















          Thank you Zim !

          – Jibeji
          Nov 20 '18 at 12:45





          Thank you Zim !

          – Jibeji
          Nov 20 '18 at 12:45


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392398%2fmenu-wont-collapse-while-clicking-on-other-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter