In jsTree , How to get Node information by node id?

javascript, jquery, jquery-plugins, jquery-selectors, jstree

Solution

If I'm understanding your question correctly, you can accomplish what you want to do like this:

var nodInfo = $("#" + providedNodeId);

var parent_id_value = nodInfo.attr("parent_id");    
var title_value     = nodInfo.attr("title");    
var version_value   = nodInfo.attr("version");
var node_name       = nodInfo.children("a").text();

alert(parent_id_value+" :: "+title_value+" :: "+version_value+" :: "+node_name);

Problem

In jsTree ,How to get Node information by node id ? I know id of following node i.e 295 then how to get complete node information ``` <item id="295" parent_id="192" title="itemTitle" version="1"> <content><name>Bhushan Sambhus</name></content> </item> ``` above xml part rendered into jsTree is as follows ``` $("#treeViewDiv").jstree({ "xml_data" : { "data" : "" + "<root>" + "<item id="295" parent_id="192" title="itemTitle" version="1">"+ "<content><name>Bhushan Sambhus</name></content> "+ "</item>" } "plugins" : [ "themes", "xml_data","ui" ] }); ``` Something like following psudo code ``` function getNodeByNodeID(node_id){ // some code // $.jstree.get_node ...... etc ? // return relatedNodeInformation; } var nodeInfo = getNodeByNodeID(providedNodeID) // psudo code // any api in jstree to get nodeInfo by providedNodeID? var parent_id_value = nodInfo.attr("parent_id"); var title_value = nodInfo.attr("title"); var version_value = nodInfo.attr("version"); var node_name = nodInfo.children("a").text() alert(parent_id_value+" :: "+title_value+" :: "+version_value+" :: "+node_name); ``` Input : 295 Output: 192 :: node_name :: 1 :: node_name Any help or guidance in this matter would be appreciated

Original source