How would I write a listener for a double-click event on a jstree object? (For example, I'd like to double-click on a tree node and paste its anchor's href
value into an input
field in a form somewhere.)
Asked
Active
Viewed 1.4k times
7

Alex Reynolds
- 95,983
- 54
- 240
- 345
-
Possible duplicate of [How can I attach custom behaviour to a double click in jsTree?](http://stackoverflow.com/questions/3674625/how-can-i-attach-custom-behaviour-to-a-double-click-in-jstree) – Rob Forrest Oct 23 '15 at 12:15
2 Answers
12
I have used something like this way back a year ago, i don't know if there's any change in the current jstree version :
jstree.bind("dblclick.jstree", function (event) {
var node = $(event.target).closest("li");
var data = node.data("jstree");
// Do some action
});
node : Contains the li that is being clicked.
data : Contains the metadata.

Nirmal
- 4,789
- 13
- 72
- 114
-
2After `// Do some action`, if I add `alert(data);` then I get `null`. – Alex Reynolds May 09 '11 at 06:17
-
This SO answer is close to yours and seems to work: http://stackoverflow.com/questions/3674625/how-can-i-attach-custom-behaviour-to-a-double-click-in-jstree/5652753#5652753 – Alex Reynolds May 09 '11 at 06:22
-
5node.data("jstree") is returning undefined in latest version ofjStree(3.1.x) So use this: `var tree = $(this).jstree(); var node = tree.get_node(evt.target); var nodePath = tree.get_path(node).join("/");` So you have both node object and tree object to invoke any tree API – TechMaze Apr 22 '15 at 19:44
6
Nirmal's solution works if you click anywhere on the jstree div. I wanted to enable double click only on the nodes themselves and not, for example, on the whitespace to the right. changing the solution a little enabled this:
$('#jstree-div a').live('dblclick',function (e) {
var node = $(e.target).closest("li");
var type = node.attr('rel');
var item = node[0].id;
// do stuff...
});
Not sure why the 'rel' and the 'id' attributes are in different places in the resulting node, but it works ;)

r00pert
- 101
- 1
- 2