title: D3.js Tree Expand All and Collapse All
body: <p>I'm building a Tree using D3.js and what I am trying to do is add two buttons, Expand All and Collapse All to the top of the page like this.</p>
  
  <p><img src="https://i.stack.imgur.com/ZUMUU.png" alt="Expand All and Collapse All in D3.js"></p>
  
  <p>When I click "Expand All", all the nodes should expand. And when I click "Collapse All", all the nodes should collapse to the root element.</p>
  
  <p>Here's my current code <a href="http://bl.ocks.org/anonymous/ab8d7f85cca6f745a107" rel="noreferrer">http://bl.ocks.org/anonymous/ab8d7f85cca6f745a107</a></p>
  
  <p>But the problem is, it isn't working. Can somebody suggest how to make it work?</p>