jsTree: adding Expand All and Collapse All buttons

The documentation for jsTree is thorough, but not particularly easy to read. If you are looking for an easy way to add “Expand All” and “Collapse All” buttons, here’s one way:

<input type="button" value="Collapse All" onclick="$('#tree_container_id').jstree('close_all');">
<input type="button" value="Expand All" onclick="$('#tree_container_id').jstree('open_all');">

where ‘#tree_container_id’ is, of course, the ID of the container node for your tree.


  1. Shoaib

    To open all
    $(“#tree_container_id”).jstree(“open_all”, -1);
    To close all
    $(“#tree_container_id”).jstree(“close_all”, -1);

Leave a Reply

Your email address will not be published. Required fields are marked *