What Code Does?
(1) On click of right arrow, It shows all child elements of root node and change the image to down arrow and on click of down arrow, it hides all child elements of root node and change the image to right arrow.
Below function does the magic. Child nodes are contained within 1 div. So if that div is visible then it makes it invisible and if it is invisible then it make it visible.
(2) On selection of root node, all child nodes are getting selected and on deselection, all gets deselected.
Below function does the magic.
(3) Also there is provision to make all nodes(root,child) checked through checkbox. Below function simply uses function I have shown in step2 and does its work.