Keep Jquery accordion menu open on current page

NN796

I am sure that i will get help in my particular case. No doubt there are many solutions to achieve this but in my case I am unable to achieve it. Following is my code to generate html dynamically using java script.

Edit 1: I just want to keep open the current pan of accordion as per href attribute of anchor tag which is in fact current page URL. This is it.

JS code to generate html:

<script>
  $.ajax({
    url: "/categories",
    type: 'GET',
    success: function(data) {
      var content = "";

      content += '<div id="category-navigation">';
      for (i = 0; i < data.length; i++) {

        content += '<div class="head">';
        content += '<label class="categoryLables">' + data[i].title;
        content += '</label>';

        content += '<div>';
        content += '<div class="boardsMargin">';
        content += '<ul>';

        for (j = 0; j < data[i].assigned_boards.length; j++) {

          content += '<li>';
          content += "<a href='/#categories/" + data[i].id + "/boards/" + data[i].assigned_boards[j].id + "'>";
          content += data[i].assigned_boards[j].name;
          content += '</a>';
          content += '</li>';
        }

        content += '</ul>';
        content += '</div>';
        content += '</div>';
        content += '</div>';
      }
      content += '</div>';

      $("#myNavigation").html("");
      $("#myNavigation").html(content);

      $('.head').accordion({
        heightStyle: "content",
        active: true,
        collapsible: true
      });


    }

  });

 </script>

HTML:

<div class="myNavigation">
</div>

Edit 2: For more clear view, this is picture of my accordion.

accordion

As a side note: I am working in ruby 2.2.1 and rails 4.1

Ahs N

You can use localStorage like so:

$(function () {
    $("#accordion").accordion();
    if (localStorage.getItem('active') != null) {
        $($('h3').get(parseInt(localStorage.getItem('active')))).trigger("click");
    }
});

$('h3').click(function () {
    localStorage.setItem('active', $(this).index("h3"));
});

Here is the JSFiddle demo :)

Note: You may also want to read about sessionStorage

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery accordion menu open middle on page load

From Dev

Open particular Jquery accordion pan based on current page URL

From Dev

Jquery accordion menu active open

From Dev

Jquery accordion menu active open

From Dev

Keep jquery dropdown menu open after opening another page of website

From Dev

Keep jquery dropdown menu open on the new page of web site

From Dev

Keep JQuery accordion open after refresh

From Dev

Accordion Menu: First menu item open on page load

From Dev

Keep accordion open on click

From Dev

Open specific Accordion menu

From Dev

Stop sliding up the current item on DC jQuery Vertical Accordion Menu

From Dev

not open second menu of accordion menu

From Dev

how to keep the first link of each accordion open while having two copies of the same accordion in the same page

From Dev

adding menu to jquery accordion

From Dev

jquery accordion menu with nested

From Dev

jQuery dotdotdot on accordion menu

From Dev

Resize Accordion Menu jQuery

From Dev

Keep bootstrap accordion open on click

From Dev

jquery Accordion - how to open the second tab by default on page loading

From Dev

Keep Jquery slideDown menu open when hovering over that menu?

From Dev

How can an accordion menu keep all the categories expanded? - JQuery Accordeon Menu

From Dev

Accordion to scroll to current open item

From Dev

jquery Accordion open and close

From Dev

jquery accordion open/close

From Dev

JQuery accordion open by default

From Dev

Accordion menu closes on page load

From Dev

JQuery accordion menu with nested accordion menus

From Dev

jquery - vertical accordion navigation menu

From Dev

jQuery sub-menu Accordion

Related Related

HotTag

Archive