Opening / closing jstree node


/ Published in: jQuery
Save to your folder(s)

Clicking on node makes it toggle between opened and closed. Nodes needs to have id attribute for this to work.


Copy this code and paste it in your HTML
  1. .bind("select_node.jstree", function (event, data) {
  2. var id = data.rslt.obj.attr("id");
  3. if (id != undefined) {
  4. if ($("li[id=" + id + "]").hasClass("jstree-open"))
  5. $("#treeViewContainer").jstree("close_node", "#" + id);
  6. else
  7. $("#treeViewContainer").jstree("open_node", "#" + id);
  8. }
  9. }
  10.  
  11. <div id="treeViewContainer">
  12. <ul>
  13.  
  14. </ul>
  15. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.