Search code examples
javascriptjqueryjstree

Check if all nodes are expanded - jstree


I'm using jstree library and I'm trying to understand how to check if the tree has all it's nodes expanded after I expand one node. This functionality I want to use in order to set a switch on/off weather all nodes are expanded or all nodes are not expanded.


Solution

  • If you want to check whether all nodes are at collapsed state or at least one node is expanded then you can use below check.

    $('#btnCheck').click(function () {
        $('#status').text("No - all nodes are collapsed");
        if($('#SimpleJSTree li.jstree-open').length)
        {
            $('#status').text("Yes - there is expanded node");
        }
     });
    

    where jsTree id is SimpleJSTree and jstree-open class is being used for expanded node.

    For complete example, you can refer https://everyething.com/jsTree-check-for-any-expanded-node