I want to clean up my code a bit.. mechanism/algorithm like suggested in my question in another post.
list item stay open on click a link or reload/refresh page
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.
Here is my html:
<ul>
<li class="menu"><a href="#">Server</a></li>
<ul>
<li class="item">
<span>
<a href="#1">Start</a>
</span>
</li>
<li class="item">
<span>
<a href="#2">Security</a>
</span>
</li>
</ul>
<li class="menu"><a href="#">GIT</a></li>
<ul>
<li class="item">
<span>
<a href="#1">blub</a>
</span>
</li>
<li class="item">
<span>
<a href="#2">wurst</a>
</span>
</li>
</ul>
</ul>
And my jQuery code:
$(document).ready(function () {
$(".item").hide();
$(".menu").click(function() {
localStorage.setItem('clickedItem', '.menu');
$(".item").hide();
$(this, ".item").show();
});
});
Here is a JSFiddle: https://jsfiddle.net/ngy5mb4q/2/
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.