My question is based on this topic, but I would like to add a few functions.
The current code looks like that:
$(document).ready(function() {
$('ol ol').hide();
$('li').click(function() {
$(this).children('ol').toggle();
});
});
* {
margin: 0;
padding: 0;
font-family: Arial;
cursor: default;
}
ol {
counter-reset: item;
}
li {
display: block;
}
li:before {
content: counters(item, ".") " ";
/* content: counters(item, ".", decimal-leading-zero) " "; */
counter-increment: item;
}
li:has(ol):before {
float: left;
/* margin-bottom: 5px; */
}
ol ol {
overflow: hidden;
}
.active {
color: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ol>
<li>Coffee
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</li>
<li>Tea
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</li>
<li>Milk</li>
<li>Cool</li>
</ol>
The following is needed:
- If you click
Coffee
orTea
, the the subordinate menu items should expand, but with a space from the left starting just below the word and not the digit, the way it was solved here. - It should only be possible to open one menu item at a time.
- The menu item clicked last should toggle the
.active
class. - If there are more than 9 menu items, all menu items should start with a 0 in front of the respective digit so that everything is still on the fitting position.
Here is an example how it can look like:
Does someone know how to do that? I would be very grateful for help.