Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all nodes in jsTree

Is there a way to clear out all nodes from a jsTree that's faster than walking through all the nodes deleting them one-by-one?

like image 362
Jeff Dege Avatar asked Jun 09 '11 19:06

Jeff Dege


4 Answers

The simplest way I have found is to simply call .empty on the div containing the tree.

$('#tree').empty();

You might choose to use a more specific selector as a parameter for empty(), but this works fine for me.

like image 62
Brad Avatar answered Nov 13 '22 12:11

Brad


$('#tree').jstree("destroy").empty();

This is what worked for me. First destroy jstree elements and associated events, and then empty the div containing jstree.

like image 13
user602599 Avatar answered Nov 13 '22 12:11

user602599


See the documentation here: http://www.jstree.com/documentation/core

.delete_node ( node )

Removes a node. Triggers an event.

mixed node

This can be a DOM node, jQuery node or selector pointing to the element you want to remove.

It seems you can just do a selector that will delete all the nodes you want, no loops required.

like image 11
Adam Terlson Avatar answered Nov 13 '22 13:11

Adam Terlson


myTree.delete_node(myTree.get_node("#").children);
like image 2
Bruno Lafont Avatar answered Nov 13 '22 12:11

Bruno Lafont