title: jQuery list items and menus method/function
body: <p>I want to clean up my code a bit.. mechanism/algorithm like suggested in my question in another post.</p>
  <p><a href="https://stackoverflow.com/questions/68784354/list-item-stay-open-on-click-a-link-or-reload-refresh-page/68805339#68805339">list item stay open on click a link or reload/refresh page</a></p>
  <p>I do not want to repeat myself over and over again. If I add more list items and menus to the code. Maybe someone can help me with a function/method to write less code.</p>
  <p>Here is my html:</p>
  <pre><code>        &lt;ul&gt;
            &lt;li class=&quot;menu&quot;&gt;&lt;a href=&quot;#&quot;&gt;Server&lt;/a&gt;&lt;/li&gt;
              &lt;ul&gt;
                &lt;li class=&quot;item&quot;&gt;
                  &lt;span&gt;
                    &lt;a href=&quot;#1&quot;&gt;Start&lt;/a&gt;
                  &lt;/span&gt;
                &lt;/li&gt;
                &lt;li class=&quot;item&quot;&gt;
                  &lt;span&gt;
                    &lt;a href=&quot;#2&quot;&gt;Security&lt;/a&gt;
                  &lt;/span&gt;
                &lt;/li&gt;
              &lt;/ul&gt;
          
            &lt;li class=&quot;menu&quot;&gt;&lt;a href=&quot;#&quot;&gt;GIT&lt;/a&gt;&lt;/li&gt;
              &lt;ul&gt;
                &lt;li class=&quot;item&quot;&gt;
                  &lt;span&gt;
                    &lt;a href=&quot;#1&quot;&gt;blub&lt;/a&gt;
                  &lt;/span&gt;
                &lt;/li&gt;
                &lt;li class=&quot;item&quot;&gt;
                  &lt;span&gt;
                    &lt;a href=&quot;#2&quot;&gt;wurst&lt;/a&gt;
                  &lt;/span&gt;
                &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/ul&gt;
  </code></pre>
  <p>And my jQuery code:</p>
  <pre><code>$(document).ready(function () {
     
      $(&quot;.item&quot;).hide();
  
      $(&quot;.menu&quot;).click(function() {
          
          localStorage.setItem('clickedItem', '.menu');
  
          $(&quot;.item&quot;).hide();
  
          $(this, &quot;.item&quot;).show();
  
      });    
  });
  </code></pre>
  <p>Here is a JSFiddle:
  <a href="https://jsfiddle.net/ngy5mb4q/2/" rel="nofollow noreferrer">https://jsfiddle.net/ngy5mb4q/2/</a></p>
  <p>I am a bit new to functions/methods, thats why I need a bit help. Maybe someone can show me an example, so that I can understand it better.</p>