JqTree getSelectNode Function

JqTree getSelectNode Function

I'm new to jqTree. I am trying to use the function: getSelectedNode found here: jqTree functions I have my tree working and being displayed using my own data as well as the sample data within this function:

 $(function() {
            $('#tree1').tree({
                data: data,
                dragAndDrop: true,
                autoOpen: 1
            });
        });

Using the jqTree function below, I only ever get "null" out on loading the page. Furthermore nothing changes when I select a node.

  var node = $('#tree1').tree('getSelectedNode');
  console.log(node);

I have also tried the given sample:

  var node = $tree.tree('getSelectedNode');
  console.log(node);

In this case I get $tree not defined

Essentially, what am I doing wrong? How does these type of jqTree functions work? Tks !

1 Answer

It appears that you have to wrap this function in a click event. But of course, the docs don't tell you that. I found the source here: jqTree I htis helps someone else.

$('#tree1').bind(
'tree.click',
function(event) {
    // The clicked node is 'event.node'
    var node = event.node;
    alert(node.name);
}

);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.