Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom class to jstree

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!

like image 397
Swapnil Shende Avatar asked Jul 27 '15 09:07

Swapnil Shende


1 Answers

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 */
like image 170
vakata Avatar answered Oct 28 '22 04:10

vakata