I have got jsTree and a button. jsTree has select_node function
.bind("select_node.jstree", function (event, data) {
// some code
})
is it possible to trigger select_node event on button click?
I have got jsTree and a button. jsTree has select_node function
.bind("select_node.jstree", function (event, data) {
// some code
})
is it possible to trigger select_node event on button click?
Share Improve this question edited Jan 20, 2012 at 13:50 greut 4,3731 gold badge31 silver badges49 bronze badges asked Jan 20, 2012 at 13:46 Iurii DziubanIurii Dziuban 1,0912 gold badges18 silver badges31 bronze badges3 Answers
Reset to default 0The way to use anything you bind
ed in jQuery is done via trigger
(or triggerHandler
).
.trigger('select_node.jstree', data)
See: http://api.jquery./trigger/
you could write a
function onSelectNode(selectedNode) {/* do stuff */}
and then you can call it in your event bind like this
.bind("select_node.jstree", function (event, data) {
onSelectNode(data.node);
})
and then instead of trying to trigger 'select_node' yourself you can just call
onSelect(treeInstance.get_selected(true)[0])
note: you must have already saved the reference of tree in a variable in global scope to access it later
treeInstance = $('#div').jstree(true);
You can trigger the select_node.jstree using trigger i.e
.trigger('select_node.jstree', data)
where data is plete node that you need to select