I have a D3.js collapsible tree which has a bunch of nodes as like shown in below figure 
Now I want to collapse all other node if a node is expanded. For example in figure if analytics node is expanded then it should collapse data node. I am refering D3.js collapsible tree - expand/collapse intermediate nodes but its not much helpful.
Change click function to this
function click(d) {
for (var i = 0; i < d.parent.children.length; i++) {
if (d.parent.children[i].name !== d.name) {
console.log(d.parent.children[i])
if (d.parent.children[i].children) {
d.parent.children[i].children = d._children;
d.parent.children[i].children = null;
}
}
};
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
};
update(d);
}
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With