I am making a basic online editing outline for coursework, working with HTML, CSS and Javascript. I want to include a tree-view functionality, that expands and collapses the parent node with one click. However, i can seem to get it to work.
<!DOCTYPE html>
<html>
<head>
<title>Editor</title>
<style>
.caret {
cursor: pointer;
user-select: none;
}
.active {
display: block;
}
</style>
</head>
<body>
<div id="inputArea">
<div id="bulletPoints" contenteditable="true"></div>
</div>
<script>
let toggler = document.getElementsByClassName("newLi");
let i;
for (i = 0; i < toggler.length; i++) {
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".newUl").classList.toggle("active");
this.classList.toggle("newLi-down");
});
}
</script>
</body>
</html>