I am struggling to implement a vertical line for the first level of list items when they are expanded and remove it when they are closed. I have tried using li::after but it doesn't seem to work. Can someone provide guidance on how to achieve this?
The vertical line should only be present along the first level of hierarchy.
I have set up a treeview with three list items and provided the code that needs to be updated to include the vertical lines.
var toggler = document.getElementsByClassName("caret");
var i;
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".nested").classList.toggle("active");
this.classList.toggle("caret-down");
});
}
ul, #main {
list-style-type: none;
}
#myUL {
margin: 0;
padding: 0;
}
li::after{
border-left 1px solid black;
}
.caret {
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.caret::before {
content: "\25B6";
color: black;
display: inline-block;
margin-right: 6px;
}
.caret-down::before {
-ms-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
.nested {
display: none;
border-left 1px solid #000
}
.active {
display: block;
border-left 1px solid #000
}
<ul id="main">
<li><span class="caret">First</span>
<ul class="nested">
<li>sub1</li>
<li>sub2</li></ul>
<li><span class="caret">Second</span>
<ul class="nested">
<li>sub1</li>
<li>sub2</li></ul>
<li><span class="caret">Third</span>
<ul class="nested">
<li>sub1</li>
<li>sub2</li>
</ul>
</li>
</li>
</li>
</ul>