I need to add a class to all child and parent nodes in jstree.
tried the below code but its not working.
$('#data').jstree({
'core' : {
'data' : [{"text" : "GROUPS","state":{"opened":true},
"children" : [{ "text" : "USERS", attributes : { class : "desired_node_class" }},{ "text" : "ADMIN"}]}
]
}
});
What am i doing wrong?. Here's a fiddle to it http://jsfiddle.net/m6yxhnrg/
Can someone correct me
Thanks in Advance!
You need to use li_attr
not attr
in your JSON as specified in the docs. Here is your updated fiddle:
http://jsfiddle.net/m6yxhnrg/1/
I added classes to all nodes, as you requested - you have to include the class data for each node.
By the way, if you are simply trying to style something maybe it will be best to skip adding custom classes and use the existing CSS classes, which are already available on each node:
#data .jstree-node { } /* this is for each LI node */
#data .jstree-anchor { } /* this is for each A node */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With