开发者

how to populate child node in jQuery Treeview in specific parent?

开发者 https://www.devze.com 2023-03-19 18:38 出处:网络
I\'m using jQuery Treeview. Is there\'s a way to populate a children开发者_C百科 node in a specific parent on onclick event? Please give me some advise or simple sample code to do this.You can access

I'm using jQuery Treeview. Is there's a way to populate a children开发者_C百科 node in a specific parent on onclick event? Please give me some advise or simple sample code to do this.


You can access the node with Javascript by using

document.getElementById('theParent')
    .getElementsByTagName('firstHierarchyTag')[n]
    .getElementsByTagName('secondHierarchyTag')[n]
    ...


Yes, it is possible, give us the HTML code then we will be able to give a very specific example.

// attach the treeview to the main ul
$("#mytree").treeview();

// listen for an event on a specific node
$("#mytreebranch").click(function() {
    var children = "<li><span class='folder'>New Children</span>"+
                   "<ul><li><span class='file'>Sub-child 1</span></li>" + 
                   "<li><span class='file'>Sub-child 2</span></li>" +
                   "</ul></li>";
     children = $(children).appendTo("#mytree");

    // add the new elements to the treeview
    $("#mytree").treeview({
        add: children
    });
});
0

精彩评论

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