Add Class to Node

1,419 views
Skip to first unread message

Joshua Foley

unread,
Mar 19, 2014, 8:06:35 PM3/19/14
to jst...@googlegroups.com
I'm having difficulty changing the data in a node after the tree has been created.

For example, the following code runs when an element on the page is clicked:

$("#parameterTree_2").jstree(true).get_node("131_2168").li_attr.class = "test";

The node's class doesn't actually update, although if I check the value of $("#parameterTree_2").jstree(true).get_node("131_2168").li_attr.class again, it still says that it is "test".

How do I go about adding a class to a node? Because obviously I'm doing something wrong here.

Ivan Bozhanov

unread,
Mar 20, 2014, 2:31:46 AM3/20/14
to jst...@googlegroups.com
The new class will be applied on the next redraw (for example close / open its parent), so either redraw the node, or add the class manually if the node exists, like so:

$("#parameterTree_2").jstree(true).get_node("131_2168").li_attr.class = "test";
$("#parameterTree_2").jstree(true).redraw_node("131_2168", true);

Or:

$("#parameterTree_2").jstree(true).get_node("131_2168").li_attr.class = "test";
document.getElementById('131_2168').className += ' test';

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages