How to access html attributes of current node in jsTree?
When using jsTree and hotkeys plugin I want to access html attributes of cur开发者_JS百科rent node.
My hotkyes code looks like and gives me undefined but the node got an ID
"c" : function (obj) {
alert($(obj).attr('id'));
,
How can I access the node's html attributes?
You can get the currently selected node by using this._get_node();
in your hotkey function, where node
is the jQuery object of the <li>
in your tree. this._get_node().attr("id")
will return the id
of the selected node.
If you want the currently hovered node however (when the user has not pressed space to select the node while traversing the tree using hotkeys) you can use:
"c" : function(event) {
var node = this._get_node(this.data.ui.hovered);
if(node) {
var id = node.attr("id");
}
}
Basic example in jsFiddle (press C
for selected node, D
for hovered node): http://jsfiddle.net/mfgLF/14/
精彩评论