How can I get the id of the selected node in a jsTree?
function createNewNode() {
alert('test');
var tree = $.tree.reference("#basic_html");
selectedNodeId = xxxxxxxxx; //insert instruction to get id here
tree.create({ data : "New Node Name" }, selectedNodeId);
}
Nodes in jsTree are essentially wrapped list items. This will get you a reference to the first one.
You can replace
$.tree.focused()if you have a reference to the tree.To get the id, take the first matched element
or you can use the jQuery attr function, which works on the first element in the set