Jon
Jon

Reputation: 105

What event is triggered when an arrow or other icon is clicked to expand a branch of a tree?

I know how to trap clicking on a node:

    // Define action when a node was clicked.
    $('#mytree').on("select_node.jstree", function (e, data) {
      // do whatever
    });

But I can't figure out which event is triggered when clicking an icon to expand a branch of a tree. I have reviewed the list of events in the documentation, but none stands out as self-evident. I tried:

// Define action when a node is expanded.
$('#mytree').on("select_node.jstree", function (e, data) {
    // do whatever
});

but it didn't get triggered. I also tried:

// Define action when a node is expanded.
$('#mytree').on("open_node.jstree", function (e, data) {
    /do whatever
});

but that gets triggered for each node when the tree is loaded, not when a specific node is clicked to expose its children.

Upvotes: 0

Views: 1021

Answers (2)

richmake
richmake

Reputation: 29

Here's a way to do it:

$('#JSTree').on("click.jstree", ".jstree-ocl", function (e)  {
    if ((this).parentElement.classList.contains('jstree-closed'))
    {selectedNode = ($(this).nextAll(".jstree-anchor").attr("id"))
     var node = $('#JSTree').jstree("get_node", selectedNode);
     alert(node.text)
     alert(node.id)}
})

Upvotes: 0

Rob
Rob

Reputation: 144

I couldn't add this as comment, have u tried click.jstree ?

$('#mytree').on("click.jstree", function (e, data) {
    //do something
});

Upvotes: 1

Related Questions