title: Display active category, sub category after page refresh
body: <p>I'm trying to display active category after page reload
  first I tried by using URL and PHP
  but its not work on sub category
  now I'm trying to achieve this by using JavaScript or jQuery.
  Below is my PHP code</p>
  <pre><code>function multilevel($connection, $parent = 0, $cat_id)
  {
  
      $side = '';
      $sql = '';
      if ($parent == 0) {
          $sql =  &quot;SELECT * FROM `categorys` WHERE parent_id = 0 ANd  cats_status = 1 ORDER BY cats_name ASC&quot;;
      } else {
          $sql =  &quot;SELECT * FROM `categorys` WHERE parent_id = $parent ANd  cats_status = 1 ORDER BY cats_name ASC&quot;;
      }
  
      $result =  mysqli_query($connection, $sql);
      // $count = mysqli_num_rows($result);
  
      while ($row = mysqli_fetch_assoc($result)) {
          if ($row['parent_id'] == 0) {
              $side .= &quot;&lt;li class='categorys'&gt;
                          &lt;h3&gt;
                              &lt;a href='?cat_id=&quot; . $row['cats_id'] . &quot;' id='&quot; . $row['cats_id'] . &quot;' class='nav-link'&gt;&quot; . $row['cats_name'] . &quot;&lt;/a&gt;
                          &lt;/h3&gt;&quot;;
          } else {
              $side .= &quot;&lt;li class='categorys'&gt;
                          &lt;h3&gt;
                              &lt;a href='?cat_id=&quot; . $row['cats_id'] . &quot;' id='&quot; . $row['cats_id'] . &quot;' class='nav-link'&gt;&quot; . $row['cats_name'] . &quot;&lt;/a&gt;
                          &lt;/h3&gt;&quot;;
          }
  
          $side .= &quot;&lt;ul class='nav nav-link collapse' id='submenu'&gt;&quot; . multilevel($connection, $row['cats_id'], $row['cats_id']) . &quot;&lt;/ul&gt;&quot;;
          $side .= &quot;&lt;/li&gt;&quot;;
      }
  
      return $side;
  }
  $cat_id = get_save_data($connection, $_GET['cat_id']);
  echo multilevel($connection, 0, $cat_id);
  </code></pre>
  <p>here is jQuery code</p>
  <pre><code>$(document).ready(function() {
      $(&quot;#accordian a&quot;).click(function() {
          var link = $(this);
          var closest_ul = link.closest(&quot;ul&quot;);
          var parallel_active_links = closest_ul.find(&quot;.active&quot;)
          var closest_li = link.closest(&quot;li&quot;);
          var link_status = closest_li.hasClass(&quot;active&quot;);
          var count = 0;
  
          closest_ul.find(&quot;ul&quot;).slideUp(function() {
              if (++count == closest_ul.find(&quot;ul&quot;).length)
                  parallel_active_links.removeClass(&quot;active&quot;);
          });
  
          if (!link_status) {
              closest_li.children(&quot;ul&quot;).slideDown();
              closest_li.addClass(&quot;active&quot;);
          }
      })
  })
  
  $(document).ready(function() {
      $(&quot;.nav-item a&quot;).on(&quot;click&quot;, function() {
          $(&quot;.nav-item.active&quot;).removeClass(&quot;active&quot;);
          $(this).parent().addClass(&quot;active&quot;);
      }).filter(function() {
          return window.location.href.indexOf($(this).attr('href').trim()) &gt; -1;
      }).click();
  });
  </code></pre>
  <p>by using PHP I'm unable to show sub category active, that's why I'm trying to achieve this by jQuery.
  Is there any way to show active category using URL parameter or maybe without URL</p>