Expand a bootstrap 4 collapsed menu with direct access












0















I have a sidebar menu with many entries and many sublevels, which looks like that :



  <div class="container-fluid">
<div class="row">
<div class="col-md-2" id="sidebar" style="margin: 5px 0">
<div class="list-group panel">
<a href="/demo" class="list-group-item">Menu</a>
<a href="#tech" class="list-group-item" data-toggle="collapse"><i class="fa fa-wrench"></i> Menu 1 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="tech" data-parent="#sidebar">
<a href="#techsub1" class="list-group-item" data-toggle="collapse">Sub 1 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="techsub1" data-parent="#techsub1">
<a class="list-group-item" href="techsub1sub1.html">techsub1sub1</a>
<a class="list-group-item" href="techsub1sub2.html">techsub1sub2</a>
</div>

<a href="#techsub2" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="techsub2" data-parent="#techsub2">
<a href="#techsub2sub1" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="techsub2sub1" data-parent="#techsub2sub1">
<a class="list-group-item" href="techsub2sub1sub1.html">techsub2sub1sub1</a>
<a class="list-group-item" href="techsub2sub1sub2.html">techsub2sub1sub2</a>
</div>
</div>
</div>

<a href="#anx" class="list-group-item" data-toggle="collapse" data-parent="#sidebar"><i class="fa fa-book"></i> Menu 2 <i class="fa fa-caret-down"></i></a>
<div class="collapse" id="anx" data-parent="#sidebar">
<a class="list-group-item" href="anx1.html">anx1</a>
<a class="list-group-item" href="anx2.html">anx2</a>
</div>

</div>
</div>

<main class="col-md-10" style="background-color: #fff; max-width: 1140px; padding-top: 30px; padding-bottom: 20px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</main>
</div>
</div>


It works well but there are so many entries in the menu that I want to use a pager on each page [Previous - Current - Next]



My concern is that when I click on Previous or Next page, the sidebar is collapsed. Is there a way to expand the according page called, but keeping it collapsed on the home page ?










share|improve this question



























    0















    I have a sidebar menu with many entries and many sublevels, which looks like that :



      <div class="container-fluid">
    <div class="row">
    <div class="col-md-2" id="sidebar" style="margin: 5px 0">
    <div class="list-group panel">
    <a href="/demo" class="list-group-item">Menu</a>
    <a href="#tech" class="list-group-item" data-toggle="collapse"><i class="fa fa-wrench"></i> Menu 1 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="tech" data-parent="#sidebar">
    <a href="#techsub1" class="list-group-item" data-toggle="collapse">Sub 1 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="techsub1" data-parent="#techsub1">
    <a class="list-group-item" href="techsub1sub1.html">techsub1sub1</a>
    <a class="list-group-item" href="techsub1sub2.html">techsub1sub2</a>
    </div>

    <a href="#techsub2" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="techsub2" data-parent="#techsub2">
    <a href="#techsub2sub1" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="techsub2sub1" data-parent="#techsub2sub1">
    <a class="list-group-item" href="techsub2sub1sub1.html">techsub2sub1sub1</a>
    <a class="list-group-item" href="techsub2sub1sub2.html">techsub2sub1sub2</a>
    </div>
    </div>
    </div>

    <a href="#anx" class="list-group-item" data-toggle="collapse" data-parent="#sidebar"><i class="fa fa-book"></i> Menu 2 <i class="fa fa-caret-down"></i></a>
    <div class="collapse" id="anx" data-parent="#sidebar">
    <a class="list-group-item" href="anx1.html">anx1</a>
    <a class="list-group-item" href="anx2.html">anx2</a>
    </div>

    </div>
    </div>

    <main class="col-md-10" style="background-color: #fff; max-width: 1140px; padding-top: 30px; padding-bottom: 20px">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    </main>
    </div>
    </div>


    It works well but there are so many entries in the menu that I want to use a pager on each page [Previous - Current - Next]



    My concern is that when I click on Previous or Next page, the sidebar is collapsed. Is there a way to expand the according page called, but keeping it collapsed on the home page ?










    share|improve this question

























      0












      0








      0








      I have a sidebar menu with many entries and many sublevels, which looks like that :



        <div class="container-fluid">
      <div class="row">
      <div class="col-md-2" id="sidebar" style="margin: 5px 0">
      <div class="list-group panel">
      <a href="/demo" class="list-group-item">Menu</a>
      <a href="#tech" class="list-group-item" data-toggle="collapse"><i class="fa fa-wrench"></i> Menu 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="tech" data-parent="#sidebar">
      <a href="#techsub1" class="list-group-item" data-toggle="collapse">Sub 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub1" data-parent="#techsub1">
      <a class="list-group-item" href="techsub1sub1.html">techsub1sub1</a>
      <a class="list-group-item" href="techsub1sub2.html">techsub1sub2</a>
      </div>

      <a href="#techsub2" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub2" data-parent="#techsub2">
      <a href="#techsub2sub1" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub2sub1" data-parent="#techsub2sub1">
      <a class="list-group-item" href="techsub2sub1sub1.html">techsub2sub1sub1</a>
      <a class="list-group-item" href="techsub2sub1sub2.html">techsub2sub1sub2</a>
      </div>
      </div>
      </div>

      <a href="#anx" class="list-group-item" data-toggle="collapse" data-parent="#sidebar"><i class="fa fa-book"></i> Menu 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="anx" data-parent="#sidebar">
      <a class="list-group-item" href="anx1.html">anx1</a>
      <a class="list-group-item" href="anx2.html">anx2</a>
      </div>

      </div>
      </div>

      <main class="col-md-10" style="background-color: #fff; max-width: 1140px; padding-top: 30px; padding-bottom: 20px">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.
      </main>
      </div>
      </div>


      It works well but there are so many entries in the menu that I want to use a pager on each page [Previous - Current - Next]



      My concern is that when I click on Previous or Next page, the sidebar is collapsed. Is there a way to expand the according page called, but keeping it collapsed on the home page ?










      share|improve this question














      I have a sidebar menu with many entries and many sublevels, which looks like that :



        <div class="container-fluid">
      <div class="row">
      <div class="col-md-2" id="sidebar" style="margin: 5px 0">
      <div class="list-group panel">
      <a href="/demo" class="list-group-item">Menu</a>
      <a href="#tech" class="list-group-item" data-toggle="collapse"><i class="fa fa-wrench"></i> Menu 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="tech" data-parent="#sidebar">
      <a href="#techsub1" class="list-group-item" data-toggle="collapse">Sub 1 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub1" data-parent="#techsub1">
      <a class="list-group-item" href="techsub1sub1.html">techsub1sub1</a>
      <a class="list-group-item" href="techsub1sub2.html">techsub1sub2</a>
      </div>

      <a href="#techsub2" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub2" data-parent="#techsub2">
      <a href="#techsub2sub1" class="list-group-item" data-toggle="collapse">Sub 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="techsub2sub1" data-parent="#techsub2sub1">
      <a class="list-group-item" href="techsub2sub1sub1.html">techsub2sub1sub1</a>
      <a class="list-group-item" href="techsub2sub1sub2.html">techsub2sub1sub2</a>
      </div>
      </div>
      </div>

      <a href="#anx" class="list-group-item" data-toggle="collapse" data-parent="#sidebar"><i class="fa fa-book"></i> Menu 2 <i class="fa fa-caret-down"></i></a>
      <div class="collapse" id="anx" data-parent="#sidebar">
      <a class="list-group-item" href="anx1.html">anx1</a>
      <a class="list-group-item" href="anx2.html">anx2</a>
      </div>

      </div>
      </div>

      <main class="col-md-10" style="background-color: #fff; max-width: 1140px; padding-top: 30px; padding-bottom: 20px">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.
      </main>
      </div>
      </div>


      It works well but there are so many entries in the menu that I want to use a pager on each page [Previous - Current - Next]



      My concern is that when I click on Previous or Next page, the sidebar is collapsed. Is there a way to expand the according page called, but keeping it collapsed on the home page ?







      javascript bootstrap-4 collapse






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 10:41









      JibejiJibeji

      437




      437
























          1 Answer
          1






          active

          oldest

          votes


















          1














          All you need to do is to add a .show CSS class to the collapsed (having .collapse CSS class) block, which you want to be expanded. See https://getbootstrap.com/docs/4.0/components/collapse/



          It can be done in two basic ways - hard-coded for each page or added dynamically/programmatically based on some parameter (probably id of desired expanded collapse)



          Passing a parameter from one to other page on redirecting is a separate question, but in case you wonder how to do it - try some URL parameters/hash or cookies/local storage






          share|improve this answer
























          • James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

            – Jibeji
            Nov 23 '18 at 12:12











          • OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

            – James Wrcsti
            Nov 23 '18 at 13:23











          • Brillant ! Thank you so much James

            – Jibeji
            Nov 23 '18 at 16:41











          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%2f53445117%2fexpand-a-bootstrap-4-collapsed-menu-with-direct-access%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














          All you need to do is to add a .show CSS class to the collapsed (having .collapse CSS class) block, which you want to be expanded. See https://getbootstrap.com/docs/4.0/components/collapse/



          It can be done in two basic ways - hard-coded for each page or added dynamically/programmatically based on some parameter (probably id of desired expanded collapse)



          Passing a parameter from one to other page on redirecting is a separate question, but in case you wonder how to do it - try some URL parameters/hash or cookies/local storage






          share|improve this answer
























          • James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

            – Jibeji
            Nov 23 '18 at 12:12











          • OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

            – James Wrcsti
            Nov 23 '18 at 13:23











          • Brillant ! Thank you so much James

            – Jibeji
            Nov 23 '18 at 16:41
















          1














          All you need to do is to add a .show CSS class to the collapsed (having .collapse CSS class) block, which you want to be expanded. See https://getbootstrap.com/docs/4.0/components/collapse/



          It can be done in two basic ways - hard-coded for each page or added dynamically/programmatically based on some parameter (probably id of desired expanded collapse)



          Passing a parameter from one to other page on redirecting is a separate question, but in case you wonder how to do it - try some URL parameters/hash or cookies/local storage






          share|improve this answer
























          • James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

            – Jibeji
            Nov 23 '18 at 12:12











          • OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

            – James Wrcsti
            Nov 23 '18 at 13:23











          • Brillant ! Thank you so much James

            – Jibeji
            Nov 23 '18 at 16:41














          1












          1








          1







          All you need to do is to add a .show CSS class to the collapsed (having .collapse CSS class) block, which you want to be expanded. See https://getbootstrap.com/docs/4.0/components/collapse/



          It can be done in two basic ways - hard-coded for each page or added dynamically/programmatically based on some parameter (probably id of desired expanded collapse)



          Passing a parameter from one to other page on redirecting is a separate question, but in case you wonder how to do it - try some URL parameters/hash or cookies/local storage






          share|improve this answer













          All you need to do is to add a .show CSS class to the collapsed (having .collapse CSS class) block, which you want to be expanded. See https://getbootstrap.com/docs/4.0/components/collapse/



          It can be done in two basic ways - hard-coded for each page or added dynamically/programmatically based on some parameter (probably id of desired expanded collapse)



          Passing a parameter from one to other page on redirecting is a separate question, but in case you wonder how to do it - try some URL parameters/hash or cookies/local storage







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 11:10









          James WrcstiJames Wrcsti

          1765




          1765













          • James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

            – Jibeji
            Nov 23 '18 at 12:12











          • OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

            – James Wrcsti
            Nov 23 '18 at 13:23











          • Brillant ! Thank you so much James

            – Jibeji
            Nov 23 '18 at 16:41



















          • James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

            – Jibeji
            Nov 23 '18 at 12:12











          • OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

            – James Wrcsti
            Nov 23 '18 at 13:23











          • Brillant ! Thank you so much James

            – Jibeji
            Nov 23 '18 at 16:41

















          James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

          – Jibeji
          Nov 23 '18 at 12:12





          James, I was probably not clear enough. As an example, I don't know how to identify that #techsub2 has to be shown when techsub2sub1sub2.html is retreived

          – Jibeji
          Nov 23 '18 at 12:12













          OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

          – James Wrcsti
          Nov 23 '18 at 13:23





          OIC, sorry for misinterpretation. In case jQuery is available, does $('#sidebar a[href="techsub2sub1sub2.html"]').parents('.collapse').addClass('show'); work for your example with #techsub2 as intended? Notice, the key attribute is the retrieved page URL from the anchor

          – James Wrcsti
          Nov 23 '18 at 13:23













          Brillant ! Thank you so much James

          – Jibeji
          Nov 23 '18 at 16:41





          Brillant ! Thank you so much James

          – Jibeji
          Nov 23 '18 at 16:41




















          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%2f53445117%2fexpand-a-bootstrap-4-collapsed-menu-with-direct-access%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

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga