Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74520

TreeView in Javascript. Collapse and Expand with a click

$
0
0

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>


Viewing all articles
Browse latest Browse all 74520

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>