Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  56] [ 4]  / answers: 1 / hits: 84244  / 14 Years ago, tue, april 6, 2010, 12:00:00

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);
}

More From » jquery

 Answers
9

Nodes in jsTree are essentially wrapped list items. This will get you a reference to the first one.



var n = $.tree.focused().get_node('li:eq(0)')


You can replace $.tree.focused() if you have a reference to the tree.



To get the id, take the first matched element



if (n.length)
id = n[0].id


or you can use the jQuery attr function, which works on the first element in the set



id = n.attr('id');

[#97147] Friday, April 2, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
willieelisham

Total Points: 201
Total Questions: 108
Total Answers: 106

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;