开发者

How to access html attributes of current node in jsTree?

开发者 https://www.devze.com 2023-03-14 03:13 出处:网络
When using jsTree and hotkeys plugin I want to access html attributes of cur开发者_JS百科rent node.

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

精彩评论

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