开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜