Accepted answer

You can do it like this:

//here chart is the div on which you want to attach the ul and li.
var myDiv ='#chart')/
.append("ul")//root ul
.append("li")//root li
.text( li name
.append("ul");//to this add ul

//note i am iterating through the data via recursion.
function makeElements(parentDOM, myData){
    //add li element
    //if children then make ul
    if (child.children.length > 0){
        var ul = parentDOM.append("ul");
      //recurse pass ul as parentDOM
      makeElements(ul, child);

Working code here

Related Query