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.)
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'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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With